Appendix B
Appendix B — Terminal Command Cheat Sheet
A quick-reference card for the most commonly used Linux terminal commands, organised
by task. Each entry shows the base command, a practical example, and a short note on
what it does or what to watch out for. For more detail on any command, run
man command or tldr command.
Reading the examples. Text in amber
shows a real example with actual arguments filled in. Words in
grey italic
in the notes column are placeholders — replace them with your own file names, paths, or values.
Navigation
| Command | Example | What it does |
|---|---|---|
| pwd | pwd | Print working directory — shows where you are right now. |
| ls | ls -la | List directory contents. -l long format, -a show hidden files (those starting with .). |
| cd | cd ~/Documents | Change directory. cd alone goes home. cd .. goes up one level. cd - goes back to the previous directory. |
| tree | tree -L 2 | Display directory as an indented tree. -L 2 limits depth to 2 levels. Install: apt install tree. |
Files & Directories
| Command | Example | What it does |
|---|---|---|
| touch | touch notes.txt | Create an empty file, or update the timestamp of an existing one. |
| mkdir | mkdir -p projects/web | Create a directory. -p creates parent directories too — no error if they already exist. |
| cp | cp -r src/ backup/ | Copy files or directories. -r required for directories (recursive). |
| mv | mv old.txt new.txt | Move or rename a file or directory. Works across directories too. |
| rm | rm -r old-folder/ | Delete files or directories. Permanent — no Recycle Bin. -r for directories, -i to confirm each deletion. |
| ln -s | ln -s /etc/nginx nginx | Create a symbolic link (shortcut). The link points to the target; deleting the link does not delete the target. |
| find | find ~ -name "*.log" | Search for files by name, type, size, or date. -type f files only, -type d directories only, -size +100M larger than 100 MB. |
| file | file mystery.bin | Identify the type of a file by its contents, not just its extension. |
| du | du -sh ~/Downloads | Disk usage of a directory. -s summary total, -h human-readable sizes. |
Viewing File Contents
| Command | Example | What it does |
|---|---|---|
| cat | cat config.txt | Print an entire file to the terminal. Good for short files. Use less for long files. |
| less | less /var/log/syslog | Page through a file. Space = next page, b = back, / = search, q = quit. |
| head | head -20 file.txt | Show the first N lines of a file (default 10). |
| tail | tail -f /var/log/syslog | Show the last N lines. -f follows the file in real time — great for watching logs. |
| grep | grep -i "error" syslog | Search for a pattern in a file. -i case-insensitive, -r recursive through directories, -n show line numbers, -v invert (show non-matching lines). |
| wc | wc -l file.txt | Word count. -l count lines, -w words, -c bytes. |
| diff | diff file1.txt file2.txt | Show differences between two files line by line. |
Editing Files
nano — beginner-friendly editor
nano file.txtOpen or create a file
Ctrl+OSave (Write Out) — press Enter to confirm
Ctrl+XExit (prompts to save if unsaved)
Ctrl+WSearch for text
Ctrl+KCut current line
Ctrl+UPaste cut text
Alt+UUndo
Ctrl+CShow cursor position (NOT copy!)
vim — powerful modal editor
vim file.txtOpen file (starts in Normal mode)
iEnter Insert mode (to type)
EscReturn to Normal mode
:wSave the file
:qQuit (fails if unsaved changes)
:wqSave and quit
:q!Force quit without saving
/wordSearch (n = next match)
Pipes & Redirection
|Pipe — send output of one command as input to another:
ps aux | grep firefox>Redirect output to a file (overwrites):
ls > filelist.txt>>Redirect output and append (does not overwrite):
echo "line" >> file.txt<Read input from a file:
sort < names.txt2>Redirect stderr (error output) to a file:
cmd 2> errors.log2>&1Redirect stderr to the same place as stdout:
cmd > out.log 2>&1&Run command in the background:
long-task.sh &;Run commands in sequence regardless of success:
cmd1 ; cmd2&&Run second command only if the first succeeded:
apt update && apt upgrade||Run second command only if the first failed:
mkdir dir || echo "exists"Permissions & Ownership
| Command | Example | What it does |
|---|---|---|
| ls -l | ls -l ~/Documents | Show permissions, owner, group, size, and date for each file. |
| chmod | chmod 755 script.sh | Change permissions. Numeric: 4=read, 2=write, 1=execute. Three digits for owner/group/others. -R recursive. |
| chmod +x | chmod +x script.sh | Add execute permission for all users (symbolic notation). |
| chown | sudo chown philip:philip file | Change owner and group. -R recursive. Requires sudo. |
| id | id | Show your UID, GID, and all group memberships. |
| groups | groups | List all groups the current user belongs to. |
| sudo | sudo apt update | Run a command as root. Password cached for ~15 minutes. Use sudo -k to clear the cache. |
Common numeric permission values:
600
rw-------
Private file — owner reads/writes only (SSH keys)
644
rw-r--r--
Normal file — owner writes, everyone reads
700
rwx------
Private directory or executable
755
rwxr-xr-x
Standard directory or executable script
775
rwxrwxr-x
Shared — owner and group write
777
rwxrwxrwx
Everyone can do everything — avoid
Package Management
apt — Ubuntu / Debian / Mint
sudo apt updateRefresh package index
sudo apt upgrade -yUpgrade all packages
sudo apt full-upgrade -yUpgrade including kernel changes
sudo apt install pkgInstall a package
sudo apt remove pkgRemove package (keep config)
sudo apt purge pkgRemove package and config files
sudo apt autoremoveRemove unused dependencies
sudo apt cleanClear download cache
apt search termSearch for packages
apt show pkgShow package details
dpkg -l | grep pkgCheck if a package is installed
dnf — Fedora / Red Hat
sudo dnf upgrade --refreshUpdate and refresh package index
sudo dnf install pkgInstall a package
sudo dnf remove pkgRemove a package
sudo dnf autoremoveRemove unused dependencies
dnf search termSearch for packages
dnf info pkgShow package details
dnf list installedList all installed packages
Flatpak — any distro
flatpak install flathub idInstall an app from Flathub
flatpak update -yUpdate all Flatpak apps
flatpak listList installed Flatpak apps
flatpak uninstall --unusedRemove unused runtimes
Processes & System
| Command | Example | What it does |
|---|---|---|
| ps aux | ps aux | grep firefox | List all running processes. Pipe to grep to filter by name. |
| top | top | Live process monitor. q to quit, k to kill a process by PID. |
| htop | htop | Friendlier process monitor with colour. F9 to kill, F6 to sort, q to quit. |
| kill | kill 1234 | Send a signal to a process by PID. kill -9 PID force-kills it immediately. |
| killall | killall firefox | Kill all processes with a given name. |
| uptime | uptime | Show how long the system has been running and the CPU load averages (1, 5, 15 min). |
| free -h | free -h | Show RAM and swap usage in human-readable format. |
| df -h | df -h | Show disk space usage for all mounted filesystems. |
| uname -r | uname -r | Show the running kernel version. uname -a shows all system info. |
| lscpu | lscpu | Show CPU architecture, cores, threads, and cache information. |
| lsblk | lsblk | List all block devices (disks and partitions) in a tree view. |
| lsusb | lsusb | List all connected USB devices. |
| dmesg | dmesg | tail -30 | Kernel ring buffer — hardware events, driver messages, boot messages. |
| reboot | sudo reboot | Restart the system. sudo shutdown -h now to power off immediately. |
Services — systemctl
| Command | Example | What it does |
|---|---|---|
| systemctl status | systemctl status ssh | Show the current state of a service — running, stopped, or failed. Shows recent log output too. |
| systemctl start | sudo systemctl start apache2 | Start a service right now (does not persist after reboot). |
| systemctl stop | sudo systemctl stop apache2 | Stop a service. |
| systemctl restart | sudo systemctl restart nginx | Stop and start a service — applies config changes. |
| systemctl reload | sudo systemctl reload nginx | Reload config without stopping the service (not supported by all services). |
| systemctl enable | sudo systemctl enable ssh | Enable a service to start automatically at boot. |
| systemctl disable | sudo systemctl disable bluetooth | Prevent a service from starting at boot. |
| systemctl --failed | systemctl --failed | Show all services that have failed. Check these regularly as part of maintenance. |
Networking
| Command | Example | What it does |
|---|---|---|
| ip addr | ip addr show | Show all network interfaces and their IP addresses. |
| ip route | ip route show | Show the routing table. The "default via" line shows your gateway. |
| hostname -I | hostname -I | Quick way to see your local IP address(es). |
| ping | ping -c 4 8.8.8.8 | Test connectivity to a host. -c 4 sends 4 packets then stops. |
| traceroute | traceroute google.com | Show the network hops between you and a destination. Install: apt install traceroute. |
| dig | dig google.com | DNS lookup — resolve a domain name to its IP address. |
| nslookup | nslookup google.com | Alternative DNS lookup tool, simpler output than dig. |
| ss | ss -tuln | Show open ports and connections. -t TCP, -u UDP, -l listening only, -n numeric ports. |
| nmcli | nmcli device wifi list | NetworkManager CLI — list WiFi networks, connect, disconnect, manage connections. |
| curl | curl -I https://example.com | Fetch a URL. -I headers only, -o file save to file, -L follow redirects. |
| wget | wget https://example.com/file.zip | Download a file. Supports resuming with -c. |
| ssh | ssh philip@192.168.1.10 | Connect to a remote machine securely. Add -p 2222 for a non-standard port. |
| scp | scp file.txt user@host:~/ | Securely copy a file to/from a remote machine over SSH. |
Logs
| Command | Example | What it does |
|---|---|---|
| journalctl -b | journalctl -b | All logs from this boot. -b -1 for the previous boot (useful after a crash). |
| journalctl -f | journalctl -f | Follow new log entries in real time. |
| journalctl -u | journalctl -u ssh | Logs for a specific service only. |
| journalctl -p err | journalctl -p err -b | Show only errors and above from the current boot. |
| journalctl --since | journalctl --since "1 hour ago" | Show logs from a specific time window. |
| tail -f | tail -f /var/log/syslog | Follow a traditional log file in real time. |
Archiving & Compression
| Command | Example | What it does |
|---|---|---|
| tar -czf | tar -czf archive.tar.gz folder/ | Create a compressed tar archive (.tar.gz). c=create, z=gzip, f=filename. |
| tar -xzf | tar -xzf archive.tar.gz | Extract a .tar.gz archive. Add -C /path/ to extract to a specific directory. |
| tar -tf | tar -tf archive.tar.gz | List contents of a tar archive without extracting. |
| zip | zip -r archive.zip folder/ | Create a .zip file. -r includes subdirectories recursively. |
| unzip | unzip archive.zip -d /output/ | Extract a .zip file. -d specifies the destination directory. |
| gzip / gunzip | gzip file.txt | Compress or decompress a single file. Creates file.txt.gz; the original is replaced. |
Terminal Keyboard Shortcuts
Productivity
TabAutocomplete command or file name. Press twice to show all options.
↑ / ↓Navigate command history.
Ctrl+RReverse search through history. Keep pressing to go further back.
Ctrl+LClear the screen (same as the
clear command).Ctrl+AJump to the start of the current line.
Ctrl+EJump to the end of the current line.
Alt+← / →Jump word by word along the current line.
Control
Ctrl+CCancel / interrupt the running command. NOT copy (use Ctrl+Shift+C).
Ctrl+ZSuspend the running process (send to background). Resume with
fg.Ctrl+DSend EOF / exit the current shell or Python/Node REPL.
Ctrl+UDelete everything from cursor to the start of the line.
Ctrl+WDelete the word immediately before the cursor.
Ctrl+Shift+CCopy selected text in the terminal.
Ctrl+Shift+VPaste into the terminal.
Getting Help
| Command | Example | What it does |
|---|---|---|
| man | man ls | Full manual page for a command. Navigate with arrow keys, search with /, quit with q. |
| --help | ls --help | Short built-in help summary — usually faster than the full man page for a quick flag reminder. |
| tldr | tldr tar | Community-written examples for the most common uses of a command. Install: apt install tldr. |
| which | which python3 | Show the full path of a command — confirms it's installed and which version will run. |
| type | type ls | Show whether a command is a binary, alias, shell built-in, or function. |
| history | history | grep apt | Show your command history. Pipe to grep to find a specific past command. |
Tip: use the man page search. If you're not sure which command you need,
man -k keyword (or apropos keyword) searches all man page summaries
for that word. For example, man -k compress lists every command related to
compression. It won't always be obvious, but it's a useful last resort before reaching for a
search engine.