Ubuntu Command Cheat Sheet

This interactive cheat sheet provides a quick reference for common Ubuntu commands. Click the copy icon next to any command to quickly copy it to your clipboard!

System Information & Monitoring

uname -a Displays all system information.
hostnamectl Shows current hostname and related details.
lscpu Lists CPU architecture information.
timedatectl status Shows system time and date.
top Displays real-time system processes.
htop An interactive process viewer (needs installation).
df -h Shows disk usage in a human-readable format.
free -m Displays free and used memory in MB.
kill <process id> Terminates a running process.

Running Commands

[command] & Runs command in the background.
jobs Displays background commands.
fg <command number> Brings command to the foreground.

Directory Navigation & Management

pwd Displays the current directory path.
cd <directory> Changes the current directory.
mkdir <dirname> Creates a new directory.

Service Management

sudo systemctl start <service> Starts a service.
sudo systemctl stop <service> Stops a service.
sudo systemctl status <service> Checks the status of a service.
sudo systemctl reload <service> Reloads a service’s configuration.
journalctl -f Follows the journal, showing new log messages.
journalctl -u <unit_name> Displays logs for a specific systemd unit.

Text Editing & Processing

nano [file] Opens a file in the Nano text editor.
cat <file> Displays the contents of a file.
less <file> Displays the paginated content of a file.
head <file> Shows the first few lines of a file.
tail <file> Shows the last few lines of a file.
awk '{print}' [file] Prints every line in a file.

Cron Jobs & Scheduling

crontab -e Edits cron jobs for the current user.
crontab -l Lists cron jobs for the current user.

Archiving & Compression

tar -czvf <name.tar.gz> [files] Compresses files into a tar.gz archive.
tar -xvf <name.tar.[gz|bz|xz]> Extracts a compressed tar archive.

File Management

ls Lists files and directories.
touch <filename> Creates an empty file or updates the last accessed date.
cp <source> <destination> Copies files from source to destination.
mv <source> <destination> Moves files or renames them.
rm <filename> Deletes a file.

Searching & Finding

grep <search_pattern> <file> Searches for a pattern within a file.
find [directory] -name <search_pattern> Finds files by name within a directory.

Package Management (APT)

sudo apt install <package> Installs a package.
apt search <package> Searches for APT packages.
apt-cache policy <package> Lists available package versions.
sudo apt update Updates package lists.
sudo apt upgrade Upgrades all upgradable packages.
sudo apt remove <package> Removes a package.
sudo apt purge <package> Removes a package and all its configuration files.

Package Management (Snap)

snap find Search for Snap packages.
sudo snap install <snap_name> Installs a Snap package.
sudo snap remove <snap_name> Removes a Snap package.
sudo snap refresh Updates all installed Snap packages.
snap list Lists all installed Snap packages.
snap info <snap_name> Displays information about a Snap package.

User Management

w Shows which users are logged in.
sudo adduser <username> Creates a new user.
sudo deluser <username> Deletes a user.
sudo passwd <username> Sets or changes the password for a user.
su <username> Switches user.
sudo passwd -l <username> Locks a user account.
sudo passwd -u <username> Unlocks a user password.
sudo chage <username> Sets user password expiration date.

Group Management

id [username] Displays user and group IDs.
groups [username] Shows the groups a user belongs to.
sudo addgroup <groupname> Creates a new group.
sudo delgroup <groupname> Deletes a group.

Networking

ip addr show Displays network interfaces and IP addresses.
ip -s link Shows network statistics.
ss -l Shows listening sockets.
ping <'host'> Pings a host and outputs results.

Netplan Configuration

cat /etc/netplan/*.yaml Displays the current Netplan configuration.
sudo netplan try Tests a new configuration for a set period of time.
sudo netplan apply Applies the current Netplan configuration.

Firewall Management (UFW)

sudo ufw status Displays the status of the firewall.
sudo ufw enable Enables the firewall.
sudo ufw disable Disables the firewall.
sudo ufw allow <port/service> Allows traffic on a specific port or service.
sudo ufw deny <port/service> Denies traffic on a specific port or service.
sudo ufw delete allow/deny -|- Deletes an existing rule.

SSH & Remote Access

ssh <user@host> Connects to a remote host via SSH.
scp <user@host>:<destination> Securely copies files between hosts.