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

CommandExampleWhat it does
pwdpwdPrint working directory — shows where you are right now.
lsls -laList directory contents. -l long format, -a show hidden files (those starting with .).
cdcd ~/DocumentsChange directory. cd alone goes home. cd .. goes up one level. cd - goes back to the previous directory.
treetree -L 2Display directory as an indented tree. -L 2 limits depth to 2 levels. Install: apt install tree.

Files & Directories

CommandExampleWhat it does
touchtouch notes.txtCreate an empty file, or update the timestamp of an existing one.
mkdirmkdir -p projects/webCreate a directory. -p creates parent directories too — no error if they already exist.
cpcp -r src/ backup/Copy files or directories. -r required for directories (recursive).
mvmv old.txt new.txtMove or rename a file or directory. Works across directories too.
rmrm -r old-folder/Delete files or directories. Permanent — no Recycle Bin. -r for directories, -i to confirm each deletion.
ln -sln -s /etc/nginx nginxCreate a symbolic link (shortcut). The link points to the target; deleting the link does not delete the target.
findfind ~ -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.
filefile mystery.binIdentify the type of a file by its contents, not just its extension.
dudu -sh ~/DownloadsDisk usage of a directory. -s summary total, -h human-readable sizes.

Viewing File Contents

CommandExampleWhat it does
catcat config.txtPrint an entire file to the terminal. Good for short files. Use less for long files.
lessless /var/log/syslogPage through a file. Space = next page, b = back, / = search, q = quit.
headhead -20 file.txtShow the first N lines of a file (default 10).
tailtail -f /var/log/syslogShow the last N lines. -f follows the file in real time — great for watching logs.
grepgrep -i "error" syslogSearch for a pattern in a file. -i case-insensitive, -r recursive through directories, -n show line numbers, -v invert (show non-matching lines).
wcwc -l file.txtWord count. -l count lines, -w words, -c bytes.
diffdiff file1.txt file2.txtShow 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.txt
2>Redirect stderr (error output) to a file: cmd 2> errors.log
2>&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

CommandExampleWhat it does
ls -lls -l ~/DocumentsShow permissions, owner, group, size, and date for each file.
chmodchmod 755 script.shChange permissions. Numeric: 4=read, 2=write, 1=execute. Three digits for owner/group/others. -R recursive.
chmod +xchmod +x script.shAdd execute permission for all users (symbolic notation).
chownsudo chown philip:philip fileChange owner and group. -R recursive. Requires sudo.
ididShow your UID, GID, and all group memberships.
groupsgroupsList all groups the current user belongs to.
sudosudo apt updateRun 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

CommandExampleWhat it does
ps auxps aux | grep firefoxList all running processes. Pipe to grep to filter by name.
toptopLive process monitor. q to quit, k to kill a process by PID.
htophtopFriendlier process monitor with colour. F9 to kill, F6 to sort, q to quit.
killkill 1234Send a signal to a process by PID. kill -9 PID force-kills it immediately.
killallkillall firefoxKill all processes with a given name.
uptimeuptimeShow how long the system has been running and the CPU load averages (1, 5, 15 min).
free -hfree -hShow RAM and swap usage in human-readable format.
df -hdf -hShow disk space usage for all mounted filesystems.
uname -runame -rShow the running kernel version. uname -a shows all system info.
lscpulscpuShow CPU architecture, cores, threads, and cache information.
lsblklsblkList all block devices (disks and partitions) in a tree view.
lsusblsusbList all connected USB devices.
dmesgdmesg | tail -30Kernel ring buffer — hardware events, driver messages, boot messages.
rebootsudo rebootRestart the system. sudo shutdown -h now to power off immediately.

Services — systemctl

CommandExampleWhat it does
systemctl statussystemctl status sshShow the current state of a service — running, stopped, or failed. Shows recent log output too.
systemctl startsudo systemctl start apache2Start a service right now (does not persist after reboot).
systemctl stopsudo systemctl stop apache2Stop a service.
systemctl restartsudo systemctl restart nginxStop and start a service — applies config changes.
systemctl reloadsudo systemctl reload nginxReload config without stopping the service (not supported by all services).
systemctl enablesudo systemctl enable sshEnable a service to start automatically at boot.
systemctl disablesudo systemctl disable bluetoothPrevent a service from starting at boot.
systemctl --failedsystemctl --failedShow all services that have failed. Check these regularly as part of maintenance.

Networking

CommandExampleWhat it does
ip addrip addr showShow all network interfaces and their IP addresses.
ip routeip route showShow the routing table. The "default via" line shows your gateway.
hostname -Ihostname -IQuick way to see your local IP address(es).
pingping -c 4 8.8.8.8Test connectivity to a host. -c 4 sends 4 packets then stops.
traceroutetraceroute google.comShow the network hops between you and a destination. Install: apt install traceroute.
digdig google.comDNS lookup — resolve a domain name to its IP address.
nslookupnslookup google.comAlternative DNS lookup tool, simpler output than dig.
ssss -tulnShow open ports and connections. -t TCP, -u UDP, -l listening only, -n numeric ports.
nmclinmcli device wifi listNetworkManager CLI — list WiFi networks, connect, disconnect, manage connections.
curlcurl -I https://example.comFetch a URL. -I headers only, -o file save to file, -L follow redirects.
wgetwget https://example.com/file.zipDownload a file. Supports resuming with -c.
sshssh philip@192.168.1.10Connect to a remote machine securely. Add -p 2222 for a non-standard port.
scpscp file.txt user@host:~/Securely copy a file to/from a remote machine over SSH.

Logs

CommandExampleWhat it does
journalctl -bjournalctl -bAll logs from this boot. -b -1 for the previous boot (useful after a crash).
journalctl -fjournalctl -fFollow new log entries in real time.
journalctl -ujournalctl -u sshLogs for a specific service only.
journalctl -p errjournalctl -p err -bShow only errors and above from the current boot.
journalctl --sincejournalctl --since "1 hour ago"Show logs from a specific time window.
tail -ftail -f /var/log/syslogFollow a traditional log file in real time.

Archiving & Compression

CommandExampleWhat it does
tar -czftar -czf archive.tar.gz folder/Create a compressed tar archive (.tar.gz). c=create, z=gzip, f=filename.
tar -xzftar -xzf archive.tar.gzExtract a .tar.gz archive. Add -C /path/ to extract to a specific directory.
tar -tftar -tf archive.tar.gzList contents of a tar archive without extracting.
zipzip -r archive.zip folder/Create a .zip file. -r includes subdirectories recursively.
unzipunzip archive.zip -d /output/Extract a .zip file. -d specifies the destination directory.
gzip / gunzipgzip file.txtCompress 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

CommandExampleWhat it does
manman lsFull manual page for a command. Navigate with arrow keys, search with /, quit with q.
--helpls --helpShort built-in help summary — usually faster than the full man page for a quick flag reminder.
tldrtldr tarCommunity-written examples for the most common uses of a command. Install: apt install tldr.
whichwhich python3Show the full path of a command — confirms it's installed and which version will run.
typetype lsShow whether a command is a binary, alias, shell built-in, or function.
historyhistory | grep aptShow 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.

Introduction to Linux — All Chapters & Appendices Complete

You have now covered everything in the course — from choosing a distro and installing Linux to configuring hardware, managing software, securing your system, keeping it healthy, and working confidently in the terminal.

Keep this appendix handy as a day-to-day reference as you explore Linux further. The more you use the terminal, the more natural it becomes.