Linux Command Cheat Sheet
The commands I actually reach for day to day, grouped by what they're for.
Download PDFNavigation & Files
pwdPrint the current working directory.
ls -laList 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.
whoamiPrint the current logged-in user.
Processes & System
ps auxList all running processes with details.
topLive 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> -fFollow live logs for a systemd service.
df -hShow disk space usage for all mounted filesystems, human-readable.
free -hShow memory and swap usage, human-readable.
Networking
ssh user@hostOpen a secure shell session on a remote machine.
scp file user@host:/pathCopy 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 -tulnList listening TCP/UDP ports on this machine.
Packages (Debian/Ubuntu)
sudo apt updateRefresh the list of available packages and versions.
sudo apt upgradeInstall 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.gzExtract a gzip-compressed tarball.
tar -czvf <file>.tar.gz <dir>Create a gzip-compressed tarball from a directory.
unzip <file>.zipExtract a .zip archive.