๐Ÿง

Linux Command Cheat Sheet

The commands I actually reach for day to day, grouped by what they're for.

Download PDF

Navigation & Files

pwd

Print the current working directory.

ls -la

List all files, including hidden ones, with details.

cd <dir>

Change directory. `cd ..` goes up one level, `cd ~` goes home.

cp -r <src> <dst>

Copy files or directories recursively.

mv <src> <dst>

Move or rename a file or directory.

rm -rf <path>

Delete recursively without confirmation. No undo โ€” use with care.

mkdir -p <path>

Create a directory, including any missing parent directories.

find <path> -name "<pattern>"

Search for files by name under a path.

Viewing & Editing

cat <file>

Print a file's full contents to the terminal.

less <file>

Page through a file. `q` to quit, `/text` to search.

head -n 20 <file>

Show the first 20 lines of a file.

tail -f <file>

Show the last lines of a file and keep watching for new ones.

nano <file>

Simple terminal text editor. Ctrl+O to save, Ctrl+X to exit.

grep -r "<text>" <path>

Search recursively for text inside files.

Permissions & Users

chmod 755 <file>

Set read/write/execute permissions (owner/group/others).

chown user:group <file>

Change the owning user and group of a file.

sudo <cmd>

Run a single command with administrator privileges.

whoami

Print the current logged-in user.

Processes & System

ps aux

List all running processes with details.

top

Live view of running processes and resource usage. `q` to quit.

kill <pid>

Ask a process to terminate gracefully. Add `-9` to force it.

systemctl status <service>

Check whether a systemd service is running.

journalctl -u <service> -f

Follow live logs for a systemd service.

df -h

Show disk space usage for all mounted filesystems, human-readable.

free -h

Show memory and swap usage, human-readable.

Networking

ssh user@host

Open a secure shell session on a remote machine.

scp file user@host:/path

Copy a file to a remote machine over SSH.

rsync -avz src/ dst/

Sync files/directories efficiently, locally or over SSH.

curl -I <url>

Fetch just the HTTP headers for a URL โ€” quick way to check a site is up.

ping <host>

Test connectivity to a host.

ss -tuln

List listening TCP/UDP ports on this machine.

Packages (Debian/Ubuntu)

sudo apt update

Refresh the list of available packages and versions.

sudo apt upgrade

Install available upgrades for installed packages.

sudo apt install <pkg>

Install a package.

sudo apt remove <pkg>

Uninstall a package (keeps config files).

Archives

tar -xzvf <file>.tar.gz

Extract a gzip-compressed tarball.

tar -czvf <file>.tar.gz <dir>

Create a gzip-compressed tarball from a directory.

unzip <file>.zip

Extract a .zip archive.