Command reference
Every program the courses type, one page each: what it is for, which package installs it, what its options do in the lessons, and which lessons teach it.
125 commands
Accounts
Debian's wrapper around
useradd: creates the home directory, copies/etc/skel, asks for a password, and with--systemproduces a service account with no login. The one to use by hand.3 options explained · 4 lessons
Reads and changes a password's lifetime and an account's expiry date.
chage -lanswers "is this account about to expire?", a question behind a fair number of logins refused on a Monday morning.3 options explained · 1 lesson
deluser
Handle with careRemoves an account. Without
--remove-homeits files stay, now owned by a UID with no name; with it, they are gone. A service still running as that account is not stopped for you.1 option explained · 1 lesson
Prints a file's full access control list, what the
+inls -lannounces without detailing. Keep one next to a backup:rsync -aandtarwithout options do not copy ACLs.1 option explained · 2 lessons
Creates a group, and nothing more. The right it stands for is built afterwards: a directory it owns, a
chmod g+s, accounts added withusermod -aG.1 option explained · 1 lesson
Changes a password, or locks an account with
-lwithout deleting it. Locking closes neither the open sessions nor SSH key access: those are two other decisions.2 options explained · 1 lesson
Adds rights to a file that the usual nine characters cannot express: one specific account for reading, one more group for writing.
ls -lthen shows only a+; the rest is read withgetfacl.1 option explained · no lesson
Opens a shell as another identity, asking for that account's password — not yours. On a server where root has no password,
sufails andsudo -iis the intended route.2 options explained · 1 lesson
Runs one command with another account's rights, root by default, and logs who asked for it. It is not "becoming root": each command is allowed or refused by
/etc/sudoers, and that file is where what an account can really do is read.6 options explained · 77 lessons
Shows or sets the mask taken off the permissions of every file created in this shell. It is why a new file is
644rather than666: the command did not decide that, the mask did.1 option explained · 2 lessons
Creates an account with exactly what you specify and nothing more: without
-mno home directory, without-sthe shell is/bin/sh. It is the low-level tool scripts call; for a person,adduserasks the right questions.1 option explained · no lesson
usermod
Handle with careChanges an existing account: its groups, its shell, its expiry, its lock. The options look alike and do not do the same thing —
-Greplaces the group list,-aGadds to it.5 options explained · 3 lessons
Edits
/etc/sudoersand checks the syntax before saving. A typo in that file takessudoaway from everyone, including whoever could fix it; this is the only reasonable way to change it.2 options explained · 2 lessons
SSH
Copies files over SSH, with
cp's syntax. Enough for one file; for a tree to keep in sync,rsynccopies only what changed.4 options explained · 1 lesson
Opens a session or runs a command on a remote machine, in an encrypted, authenticated channel. The first connection asks you to check the server's fingerprint; it is the only moment when that check means anything.
7 options explained · 6 lessons
Loads a private key into the agent for the session, which saves retyping the passphrase — and which lends the key to everything that talks to the agent, including a remote host when
-Ais on.4 options explained · 1 lesson
Holds decrypted private keys in memory and signs on
ssh's behalf. It does nothing untilssh-addhands it something, andeval "$(ssh-agent -s)"is what makes the shell aware of it.1 option explained · 1 lesson
Creates a key pair, changes its passphrase, or prints a fingerprint. The private key never leaves the machine it was made on; the public one is copied wherever you want to log in.
7 options explained · 4 lessons
The SSH server itself.
sshd -tvalidates the configuration before a restart andsshd -Tprints what actually applies, first obtained value per keyword — which the file does not show.4 options explained · 5 lessons
Reading the system
The space on each filesystem, in blocks or with
-iin inodes. A "full" disk whiledf -hshows room is almost always adf -iat 100%.3 options explained · 9 lessons
The kernel's message buffer: disks detected, hardware errors, processes killed by the OOM killer. When a service dies without writing anything to its own log, this is where the reason is.
1 option explained · no lesson
The space a directory and its contents actually take.
dfsays how much is missing;du -sh /* | sort -hsays where it went.3 options explained · 5 lessons
RAM and swap: used, free, and above all
available, which counts reclaimable cache. A machine whosefreecolumn is near zero is fine;availableis the one to read.1 option explained · 3 lessons
Measures disk activity: throughput, requests, wait time, utilisation. A
%utilnear 100 with low throughput points at a disk saturated by small writes, not a full disk.5 options explained · 1 lesson
Recent logins and reboots, read from
wtmp. It dates a reboot without a trawl through the journal, and shows who was logged in when an incident happened.1 option explained · no lesson
Rotates, compresses and removes log files according to
/etc/logrotate.d/. It runs once a day from a timer;logrotate -dreplays the configuration without touching anything.1 option explained · 1 lesson
The distribution's name and version, also held in
/etc/os-release. The answer to the first question of every fix: "which release are you on?"1 option explained · 1 lesson
Breaks a path down component by component, with each one's permissions. A "Permission denied" on a readable file comes from a parent directory without
x, and this is the command that shows it.1 option explained · 2 lessons
The same readings as
sar, per process: which PID burns the CPU, writes to disk, or switches context too often. The link between "the machine is slow" and "it is this program".1 option explained · 1 lesson
Resolves a symbolic link, and with
-fthe whole chain to the real file. It is what says which release acurrentreally points at after a deploy.1 option explained · 6 lessons
The quota report of a filesystem: who uses what, who is over their soft limit and since when. Read it before chasing a mysterious fault on an account that "cannot write any more".
1 option explained · 1 lesson
Reads back the load history
sysstatcollects every ten minutes: CPU, memory, disk, network, by time slot. It answers "what was the machine doing at 3 a.m." when nobody was watching.5 options explained · 1 lesson
Sets an account's or a group's disk quotas on a filesystem mounted with the quota options. Without those mount options the command succeeds and limits nothing.
3 options explained · no lesson
The live state of processes, refreshed. Useful for what is consuming now; useless for what was consuming an hour ago, which only
sarkept.4 options explained · 2 lessons
The running kernel, with
-rits exact version. Compare it with whatdpkginstalled: if they differ, the machine is waiting for a reboot.1 option explained · 1 lesson
Chooses which of several installed programs answers a generic name — which
editor, whichjava. It is not a version manager: all it does is move a symbolic link.1 option explained · 1 lesson
Processes
Sends a signal to a PID:
TERMby default, which asks the process to stop,KILLwhich asks nothing. The-9in this site's name is the second: it lets the process neither close its files nor write anything.2 options explained · 2 lessons
Finds PIDs by name or pattern, without the
grepthat matches itself.pgrep -ashows the command too, which saves killing the wrong process at the next step.3 options explained · 4 lessons
pkill
Handle with careSends a signal to every process whose name matches the pattern. The pattern is a regular expression matching part of the name:
pkill nodereachesnode_exportertoo.1 option explained · 1 lesson
The list of processes at this instant, with PID, owner and command.
ps auxshows everything;ps -o pid,ppid,cmdpicks the columns, which makes the output readable by a script.5 options explained · 5 lessons
Processes as a tree, each child under its parent. It is how you see that an orphan
nodeis the grandchild of abashsomebody closed, and not a service.1 option explained · 1 lesson
Files
chmod
Handle with careChanges permissions.
chmod 777makes the error message go away, and the problem with it — the problem being that anyone can now write that file.2 options explained · 4 lessons
chown
Handle with careChanges a file's owner and group. A service that "cannot write" to its own directory has almost always a missing
chownafter a copy made by root.2 options explained · 2 lessons
Copies files. Without
-athe copy loses owner, timestamps and symbolic links; fine for a working file, wrong for a configuration or a backup.4 options explained · 2 lessons
Walks a tree and selects files by their properties: name, size, date, owner, permissions. Each test is an option, and
-execor-deleteacts on what is left; run it without the action first.17 options explained · 8 lessons
Copies a file while setting owner, group and mode in one command —
install -o root -g root -m 0644. It iscpthenchownthenchmod, without the window where the file has the wrong rights.4 options explained · 3 lessons
Creates a link: hard by default, symbolic with
-s.ln -sfnreplaces an existing link in one operation, which deployment throughcurrentrequires.3 options explained · 6 lessons
Lists a directory's contents.
ls -lshows the nine permission characters, the owner and the group — the three things to read before concluding a refused access is a bug.5 options explained · 14 lessons
Creates a directory.
mkdir -palso creates missing parents and does not complain if the directory exists — which makes the command rerunnable, but it still fails if a file has that name.1 option explained · 2 lessons
Moves or renames. On the same filesystem it is an instant rename, which is what makes switching a
currentlink atomic; across two disks it is a copy followed by a delete.4 options explained · 3 lessons
rm
Handle with careDeletes files, with no bin and no confirmation. What
rm -rfremoves is gone; the only protection is what you typed before Enter, and an empty variable turns/var/www/$appinto/var/www/there.4 options explained · 3 lessons
Everything the system knows about a file: inode, permissions in octal, modification and change times, link count. It is
ls -lwith nothing rounded or left out.2 options explained · 6 lessons
Creates an empty file, or updates an existing file's timestamp. The empty file that says "this script has run" or switches a rule on (
/etc/cron.allow) is often made this way.1 option explained · 2 lessons
Prints an indented tree, what
ls -Rdoes less legibly.tree -L 2caps the depth, which makes a deployment directory fit on one screen.1 option explained · 1 lesson
truncate
Handle with careSets a file's size, cutting it or extending it with zeros.
truncate -s 0empties a log without deleting it, so without breaking the descriptor a process keeps open on it.1 option explained · no lesson
Text
Processes text field by field and line by line, with a small language.
awk '{print $2}'is enough to pull out a space-separated column, whichcutdoes badly.1 option explained · 2 lessons
Extracts columns from text, by character or by field with
-dand-f. Enough for/etc/passwd;awktakes over when the separator is a variable run of spaces.2 options explained · no lesson
The differences between two files, line by line.
diff -uproduces the formatgitandpatchread, and it is what goes into a report to show what changed in a configuration.1 option explained · 1 lesson
Searches for a pattern in files or in what is piped to it, and returns the line — or with
-qonly an exit status, which makes it a test in a script. The pattern is a regular expression unless-F.9 options explained · 17 lessons
The first lines of a file or a stream.
head -1on a command's output keeps its first line, which is often all a script needs.1 option explained · 3 lessons
Joins files line by line, side by side. With
-sd+it turns a column of numbers into1+2+3, whichbccan add up.2 options explained · no lesson
Sorts lines.
sort -hunderstandsdu -hsizes,sort -nnumbers, and with no option the sort is alphabetical — where10comes before9.3 options explained · 2 lessons
The last lines of a file, and with
-fthe ones arriving as they come. For a systemd service,journalctl -fis the same thing without having to know the file's path.2 options explained · 10 lessons
Writes what it receives both to a file and to standard output.
sudo teeis how you write a root-owned file from a pipe, wheresudo echo > filefails.1 option explained · 1 lesson
Replaces or deletes characters in a stream:
tr -d '\r'strips the Windows line endings that make a script "not found" while it is right there.2 options explained · no lesson
Removes adjacent repeated lines, or with
-ccounts them. It sees only neighbours:sort | uniq -cis the pair, anduniqalone on an unsorted file removes nothing.1 option explained · 1 lesson
Counts lines, words and bytes.
wc -lon the output of agrepor anlsturns a list into a number — the shape a check takes in a script.2 options explained · 1 lesson
Builds and runs a command from what it reads on standard input. With
find -print0 | xargs -0, file names containing spaces stop being split in two.2 options explained · 1 lesson
Shell
The default interactive shell of human accounts on Ubuntu, and the interpreter of most administration scripts.
bash -nchecks a script's syntax without running it;bash -xshows each command as it runs.2 options explained · 1 lesson
Edits an account's table of scheduled jobs. On a systemd machine a timer does the same with a log, a status and catch-up of missed runs —
crontabis what you will find on existing machines.2 options explained · 2 lessons
The date and time, in the format you ask for.
date -u +%Y%m%dT%H%M%SZnames a backup or a release so it sorts;date -d @1700000000translates a Unix timestamp.4 options explained · 2 lessons
Detaches a job from the shell that started it, so it survives the terminal closing. A rescue, not a method: a service that has to run needs a systemd unit.
1 option explained · 1 lesson
Prints the environment, or runs a command in a modified one. On a script's first line,
#!/usr/bin/env bashfindsbashwherever it is installed.1 option explained · 1 lesson
Takes a lock on a file for the duration of a command, so a second instance waits or gives up. It is what keeps a timer-launched backup from overlapping the previous one.
5 options explained · 1 lesson
The processes started from this shell and still attached to it, with their job numbers. What is listed here dies with the terminal;
disownortmuxare the ways to avoid that.2 options explained · 1 lesson
Sets the shell's behaviour.
set -euo pipefailat the top of a script stops it at the first failing command, the first undefined variable, and an error in the middle of a pipe — instead of carrying on as if nothing happened.3 options explained · 2 lessons
On Debian and Ubuntu,
/bin/shisdash, notbash. A script that starts with#!/bin/shand uses[[, arrays orsourcefails — in production, not in the terminal you tested it in.1 option explained · 1 lesson
systemd
Reads the systemd journal, by unit (
-u), by period (--since), by boot (-b), live (-f). It is where a service's output went when it writes to no file.19 options explained · 25 lessons
shutdown
Handle with careHalts or reboots the machine, now or at a stated time, warning open sessions.
shutdown -ccancels what is scheduled.2 options explained · 1 lesson
Drives systemd units: start, stop, enable at boot, read the state.
statussays what is happening now,is-enabledwhat will happen at the next boot; those are two different questions.19 options explained · 47 lessons
Lists the unit files you have overridden or replaced, and how they differ from the package's. It answers "what was changed on this machine" without a trawl through
/etc/systemd.1 option explained · 1 lesson
Runs a command as a transient unit, with a journal and limits, without writing a unit file.
--on-active=10mschedules it once, whatatused to do.2 options explained · 1 lesson
Network
Obtains and renews Let's Encrypt certificates by proving control of the domain, and installs a timer for renewal.
certbot renew --dry-runrehearses the procedure without issuing anything.5 options explained · 2 lessons
Sends an HTTP (or other) request and shows the response.
curl -Ireads only the headers,-vshows the whole exchange, TLS included — that is how you tell "the server answers badly" from "the server does not answer".12 options explained · 17 lessons
Queries the DNS and shows the raw answer, with the TTL and the server that answered.
dig +shortfor the value;dig @1.1.1.1to ask a specific resolver rather than the local cache.1 option explained · 11 lessons
iptables
Handle with careLinux's historical rule-based firewall; on recent Ubuntu, a compatibility layer over nftables. Rules live in memory: what you add is gone at reboot unless something saves it.
4 options explained · 1 lesson
A minimal SMTP client that hands a machine's mail to an authenticated relay, without running a mail server. It is what lets
cronand scripts send an alert.1 option explained · 1 lesson
Opens a raw TCP or UDP connection to a port, or listens on one.
nc -zv host 5432says whether the port is open before the database gets blamed.3 options explained · 4 lessons
nft
Handle with careThe nftables firewall tool, which replaces
iptables.nft list rulesetshows the whole set of rules actually loaded, whichever tool put them there —ufwincluded.1 option explained · 1 lesson
The web server and reverse proxy of the hosting courses. The command itself is mostly for
nginx -t, which validates the configuration before a reload: an invalid configuration reloaded leaves the old one running, without saying so loudly.3 options explained · 11 lessons
Scans a machine's ports from outside and shows what an attacker would see. Run it on your own servers after every firewall change — and only on your own.
3 options explained · 1 lesson
The TLS toolbox:
openssl s_clientconnects and shows the certificate the server actually presents,openssl x509reads a certificate on disk. The first is what you need when the browser says "not secure" without saying why.6 options explained · 3 lessons
Sends ICMP packets and times the reply. It proves a machine is reachable at the IP level; it says nothing about port 443, and a firewall dropping ICMP makes it fail on a perfectly healthy server.
1 option explained · 2 lessons
Reads and changes Postfix's configuration.
postconf -nprints only what differs from the defaults — the view you need when working out why mail is not leaving.1 option explained · 1 lesson
The open sockets: who listens on which port, which connections are established, and with
-pwhich process.ss -tlnpis the command that answers "is something already listening on 80?"4 options explained · 14 lessons
Captures the packets crossing an interface and prints them, filtered by host, port or protocol. The final arbiter: when two machines disagree about what was sent,
tcpdumpshows what actually went over the wire.5 options explained · 1 lesson
Downloads a file from a URL to disk, resuming where it stopped with
-c. Wherecurlis for examining a response,wgetis for keeping it.1 option explained · 1 lesson
Integrity and confinement
Fingerprint-based intrusion detection: a baseline of the files, then a report of what changed. Worth only as much as a baseline taken on a clean machine and kept off it.
1 option explained · 1 lesson
Loads, reloads or removes an AppArmor profile.
apparmor_parser -rreloads a changed profile without restarting the service it confines — the command you want when a service is allowed to write a file and AppArmor refuses it.1 option explained · 1 lesson
Compares installed files with their package's checksums. A binary changed without
dpkgknowing is either an intrusion or a forgotten emergencycp; either way it is what you needed to know.4 options explained · 1 lesson
Git
The version control tool, used here for configuration files as much as for code: who changed what, when, and how to go back.
git statusandgit logare the two commands to know before any other.16 options explained · 9 lessons
Packages
Adds a package source (usually a PPA) and its key. Every source added is a third party you trust for everything it publishes; the list should stay short.
1 option explained · no lesson
The package management interface for a human:
update,upgrade,install, with a progress bar and output that changes between versions — which makes it unfit for scripts.2 options explained · 5 lessons
The same as
apt, with stable output and options meant for scripts:apt-get install -yin an installation script,aptin a terminal.1 option explained · no lesson
The low-level package manager: installs a
.deb, lists what is installed (dpkg -l), says which package a file belongs to (dpkg -S). It does not resolve dependencies — that isapt's job.6 options explained · 4 lessons
Asks a package's configuration questions again — the time zone, the locales, the keyboard. The intended way to change what installation asked once.
1 option explained · no lesson
The JavaScript runtime the hosting courses' applications run on.
node --versionis the first thing to compare between the machine where it works and the one where it does not.2 options explained · 2 lessons
Node's package manager.
npm ciinstalls exactly whatpackage-lock.jsondescribes, whichnpm installdoes not guarantee — andciis what a deployment should call.2 options explained · 4 lessons
Installs packages that are confined and auto-updated by Canonical. Updates are deferred more than they are switched off — worth knowing before installing a service this way on a server.
2 options explained · 1 lesson
Transfer and archives
Decompresses a
.gz, replacing the archive with the file.gunzip -cwrites to standard output without touching the archive, which lets you read a rotated log without unpacking it to disk.1 option explained · 1 lesson
Compresses a file, replacing it with its
.gzversion.gzip -kkeeps the original; without it, it disappears, which surprises the first time on a log still open.2 options explained · 2 lessons
rsync
Handle with careSynchronises two trees by transferring only the differences, locally or over SSH.
-akeeps permissions, dates and links;-nrehearses without writing, and that is where to start.9 options explained · 6 lessons
Computes or checks a file's SHA-256 digest.
sha256sum -ccompares a download with the published digest — the only proof the file received is the one announced.1 option explained · 1 lesson
Bundles a tree into one file, and unpacks it. Without
--acls --xattrsit loses ACLs; without-pon extraction, permissions follow yourumaskrather than the archive.10 options explained · 2 lessons
Encryption
Encrypts, signs and verifies files with public keys. Here it encrypts backups before they leave the machine and checks package signatures — two uses where the private key must be backed up elsewhere, or the encrypted backup is worth nothing.
19 options explained · 1 lesson
Terminal sessions
A terminal session that survives disconnection: what runs inside carries on when SSH drops, and is found again with
tmux attach. For a long operation started by hand, it is the insurance that a network drop will not kill it.4 options explained · 1 lesson
Containers
docker
Handle with careBuilds and runs containers.
docker ps,docker logsanddocker execare the troubleshooting trio;docker composedescribes several containers in a file rather than in a two-hundred-character command line.20 options explained · 7 lessons
Databases
dropdb
Handle with careDeletes an entire database.
--if-existsavoids the error when it does not exist, which makes a script rerunnable — and also makes the command silent.1 option explained · no lesson
MariaDB's interactive client, the counterpart of
psql.mariadb -eruns a query from a script;SHOW DATABASESandSHOW GRANTSare the first two things to look at on an unfamiliar server.1 option explained · 1 lesson
Exports a MariaDB database as SQL.
--single-transactiongets a consistent copy of InnoDB tables without locking them, which a backup on a live service requires.5 options explained · 1 lesson
Exports one database as SQL or in archive format, consistently, without stopping the service. It is the logical backup; until a restore has been tried, it is only a file.
2 options explained · 2 lessons
Exports every database and what
pg_dumpleaves out: the roles and their passwords.pg_dumpall --globals-onlybeside onepg_dumpper database is the combination that really restores.1 option explained · 1 lesson
Says whether a PostgreSQL server accepts connections, through an exit status. The readiness test of a deployment script or a
healthcheck, with no password and no query.1 option explained · no lesson
pg_restore
Handle with careRestores a
pg_dump -Fcarchive, wholly or in part (-tone table).-llists the archive's contents without restoring anything; that is where to start.1 option explained · 1 lesson
PostgreSQL's interactive client.
psql -cruns a query from a script;\l,\dtand\duanswer the first three questions — which databases, which tables, which roles.6 options explained · 12 lessons
