Basics
-
cat — print a whole file
The cat command prints a file's contents to the terminal and joins several files into one stream.
5 mincatcat -ncat -A -
lsblk — block devices
A tree of disks, partitions, and logical volumes — size, filesystem, mountpoint.
3 minlsblklsblk -flsblk -o -
Getting help at the terminal
How to quickly find a command's options: man, --help, apropos and tldr; how to read a man page.
4 mincmd --helpman cmdman -
Service
What a service is, how it differs from an ordinary program, and how to manage it.
5 minsystemctl statussystemctl startsystemctl stop -
fdisk and parted — partition a disk
fdisk and parted write a partition table (GPT or MBR) and partitions to a disk; parted -s runs without prompts.
7 minlsblkfdisk -lparted -
less — page through a long file with search
The less pager shows a long file or command output screen by screen — scroll, search by word, follow the end.
5 minlessless -Nless -S -
blkid — filesystem UUID, label and type
The blkid command prints the UUID, label and type of the filesystem on a device — what goes into /etc/fstab.
5 minblkidblkid -sblkid -L -
head — the first lines of a file
The head command prints the beginning of a file or of command output — 10 lines by default, -n sets how many.
4 minheadhead -nhead -c -
tail — the last lines and following a log
The tail command prints the end of a file, and with -f it keeps showing new lines as they are appended to a log.
5 mintailtail -ntail -f -
apt / dpkg — package management
Installing, upgrading, and removing packages on Debian/Ubuntu; apt and dpkg.
4 minapt updateapt installapt purge -
Basic file commands
Navigation and files — ls, cd, cp, mv, rm, cat, less, head, tail, terminal copy-paste.
8 minls -lahcd dirpwd -
File permissions
The Unix permission model — read/write/execute, owner/group/other, special bits.
6 minls -lnamei -lchmod -
Processes
Viewing processes, signals and priorities; finding the processes that hog CPU or memory.
5 minps auxps -eopgrep -a -
cd — changing directory
Moving around the filesystem: cd, cd -, cd ~, cd .., pushd/popd, CDPATH.
4 mincd dircdpushd dir -
ls — list directory contents
The ls command lists files and directories with permissions, owner, size and modification time, hidden ones too.
6 minlsls -lls -la -
ps — list processes
The ps command lists running processes with PID, owner, state, CPU and memory use, and the command line.
5 minpsps auxps -ef -
mkdir — creating directories
Creating directories: -p (with parents), -m (permissions right away), brace expansion, rmdir.
3 minmkdir -pmkdir -mrmdir empty -
top — processes and load in real time
The top program refreshes the process list, CPU load, memory and load average every few seconds.
5 mintoptop -otop -u -
The kernel
What the Linux kernel is, what it does, and how to check its version and parameters.
4 minuname -runame -acat -
kill — send a signal to a process
The kill command sends a signal to a PID — ask it to exit (TERM), reload settings (HUP), or end it at once (KILL).
6 minkillkill -TERMkill -HUP -
mc — a terminal file manager4 min
A two-panel file manager for the terminal: navigation, copying, an editor, SFTP.
-
pgrep — find a process PID by name
The pgrep command prints the PIDs of processes by name or command line, owner and parent — no ps or grep needed.
5 minpgrep nginxpgrep -lpgrep -a -
shellcheck — checking scripts before they run
shellcheck reads a bash or sh script without running it and finds bugs: unquoted variables, unchecked cd.
7 minshellcheckshellcheck -fshellcheck -S -
stat — file metadata
Full file information — size, permissions, owner, timestamps (atime/mtime/ctime), inode.
4 minstat filestat -cls -lc -
Bash scripts: running, variables, arguments
A script is a text file of shell commands: the #! line picks the interpreter, arguments arrive in $1, $2 and "$@".
9 minset -euochmodbash -
file — determining file type
Figuring out what's inside a file (text, ELF, archive, image) by content, not by extension.
3 minfile ffile -ifile -b -
cp — copy files and directories
The cp command copies files and directories, with overwrite prompts, preserved permissions and times, recursively.
5 mincpcp -rcp -a -
which / type / whereis — where a command lives
Find out which binary will run, whether it's a builtin or an alias, where it lives, and its man page.
4 mintype -acommand -vwhich cmd -
mv — move or rename
The mv command renames a file or directory and moves it elsewhere; it silently replaces an existing target.
5 minmvmv projectmv -i -
tee — output to a file and the screen
Splits a stream: writes to a file AND shows it on screen; sudo tee to write into protected files.
3 mincmdecho x -
Exit codes: $?, && and ||
An exit code is a number from 0 to 255 that a command reports: 0 means success, anything else a failure or a "no".
10 minlsgrep -qmkdir -
alias — command shortcuts
Short names for long commands; temporary and permanent via ~/.bashrc; why alias is invisible in scripts.
4 minaliasunalias llecho -
rm — remove files and directories
The rm command deletes files and directories at once, with no trash; -i and -I ask first, -r removes a tree.
6 minrmrm -irm -I -
ln — symbolic and hard links
Symlinks (ln -s) and hard links: how they differ, when to use which, common mistakes with relative paths.
4 minln -sln -sfreadlink -f -
test, [ ] and [[ ]] — checking conditions7 min
test and [ ] check a file, a string or a number and answer with a code: 0 is yes, 1 is no; [[ ]] is the bash version.
-
echo — printing text
Printing strings and variables; -n and -e, escaping, when to prefer printf.
3 minechoecho -nprintf -
grep — searching text
The grep command finds lines matching a pattern in files and command output: regex, recursion, context.
4 mingrep -igrep -rngrep -v -
sudo — running commands as another user
Grants temporary root rights via sudoers; edit the file only through visudo, or a mistake locks everyone out of sudo.
5 minapt updatesudoeditvisudo -f -
Background jobs in the shell — &, jobs, nohup
Running things in the background, shell job control, surviving logout.
4 mincmdjobs -lfg -
uptime, who, w — who is on the system and the load
Compare load average to the core count (nproc), not an absolute threshold — the three numbers mean nothing without it.
4 minuptimenprocw -
wc — count lines, words and bytes
The wc command counts lines (-l), words (-w), bytes (-c) and characters (-m) in a file or in command output.
4 minwcwc -lgrep error -
Paths — basename, dirname, realpath
Splitting a path into a name and a directory, getting an absolute path; a script's own directory.
3 minbasenamedirnamerealpath -
sort — sort lines
The sort command orders lines of a file or command output: as text, as numbers (-n), by field (-k), reversed (-r).
6 minsortsort -nsort -rn -
uniq — remove or count repeated lines
The uniq command collapses adjacent identical lines and counts them with -c; sort almost always comes before it.
5 minsort file -
How a command is built — options and arguments
A terminal line is a command name, options (-l, --all) and arguments; the shell splits it into words at spaces.
5 minls -lls -lals --all -
cut — cut fields out of lines
The cut command takes fields out of every line by a delimiter (-d and -f) or characters by position (-c).
5 mincutcut -c1-8cut -f2 -
Glob patterns and brace expansion
Shell substitutions — * ? [] {} — and how they differ from regular expressions.
4 minmkdir -pcpecho -
Output redirection and pipelines
The shell sends a command's input and output to a file or another command — >, >>, 2>&1, /dev/null, the | pipe.
6 mincmdcmd1 -
find — searching for files
Finding files by name, size, time, permissions; acting on what's found.
4 minfind -
Users and groups
Linux accounts and groups; usermod -G without -a replaces all of a user's supplementary groups instead of adding one.
5 minid aliceuseradd -musermod -aG -
useradd — create a user
The useradd command creates a user account with a home directory, shell, groups and UID; passwd sets the password.
6 minuseradd -mpasswd aliceuseradd -r -
passwd — change or lock a password
The passwd command changes your own password; as root it sets, locks and shows the passwords of other users.
6 minpasswdpasswd alicepasswd -S -
usermod — change an account and its groups
The usermod command changes an existing account — groups, login shell, home directory, name and locking.
6 minusermod -aGusermod -rGusermod -G -
Symbolic and hard links
The difference between a symlink and a hard link, when to use which, broken links.
4 minln -sln -sfnreadlink -f -
chmod / chown — permissions and ownership
Changing permissions (chmod) and owner/group (chown) — numeric and symbolic syntax, umask, chgrp.
6 minchmodchownchown -R -
sed and awk — editing and fields in a text stream
sed edits and deletes lines by pattern, awk splits lines into fields and computes over them, line by line.
10 minsed -nsedawk -
umask — the mask for new files and directories
umask is a process mask: which permissions to remove from a new file (from 666) and directory (from 777).
6 minumaskumask -Stouch -
Regular expressions — patterns for grep, sed and awk
A regular expression is a pattern that many strings match; grep searches by it, sed replaces by it, awk selects lines.
6 mingrep -igrep -Egrep -
tar — archiving and extracting files
Packs files into a compressed archive; an archive with no top directory dumps its files into the current directory.
4 mintar czftar xzftar tvzf -
rsync — file synchronization and copying
Copies only the differences between trees; --delete mirrors the source into the destination, removing anything extra.
4 minrsync -avzPrsync -avznrsync -avz -
xargs — building arguments from a stream
Turns stdin lines into a command's arguments; without -0, file names with spaces and newlines break the parsing.
3 minfind -
restic — deduplicated backups
Incremental encrypted backups with snapshots; without the password the repository cannot be decrypted at all.
4 minrestic initrestic backuprestic snapshots -
sort, uniq, cut, wc, tr — text stream processing
Small pipeline utilities; uniq only removes adjacent duplicates, so it almost always needs sort before it.
5 minsort -usort filecut -
diff and patch — comparing and applying changes
Comparing files and applying patches: diff two configs, see what changed, apply a patch.
4 mindiff -udiff -qrdiff -
jq — processing JSON on the command line
Parsing and filtering JSON on the command line — fields, arrays, filters, formatting.
4 minjqjq -rjq --arg -
Environment variables and PATH
Environment variables: env, export, $PATH, ~/.bashrc and profiles; where "command not found" comes from.
4 minechoenvprintenv -
git: change history, undo and a remote repository
A version control system: who changed what in the files, how to get back a working version and exchange changes.
15 mingit statusgit diffgit add -
printf and echo — printing text in scripts
Formatted output in the shell — more reliable than echo, formats and special characters.
4 minprintfprintf -v -
GPG — encryption and signatures
GnuPG: GPG keys, encrypting files, signing and verifying, symmetric mode with a passphrase.
5 mingpg -cgpg -dgpg -e -
vim — editing files in the terminal
The bare minimum for editing configs; Esc always returns to Normal mode, where letters are commands, not text.
4 mini -
Ansible: inventory, modules and one-off commands
Configures servers over SSH: from an inventory and playbooks it brings machines to a described state, no agent needed.
9 minansible -iansible-inventory -iansible-playbook -i -
nano — a simple console editor
A friendly console editor — save, quit, search, for editing config files.
3 minnano filenanonano -w -
ansible-playbook: running a playbook
Runs an Ansible playbook on the inventory machines and reports ok, changed, skipping or failed for each task.
14 minansible-playbook -i -
tmux — terminal multiplexer
Keeps a terminal session alive on the server after an SSH drop; sessions live in memory and don't survive a reboot.
4 mintmux newtmux lstmux attach -
screen — terminal multiplexer
Keeps a terminal session alive on the server after an SSH drop; sessions live in memory and don't survive a reboot.
4 minscreen -Sscreen -lsscreen -r -
watch — periodically repeat a command
Repeats a command every N seconds on one screen; without quotes, a pipeline goes to the shell, not the command.
3 minwatch -n1watch catwatch -
at — a one-time scheduled job
Run a command once at a given time — unlike cron's recurring schedule.
4 minechoat nowat -f -
flock — preventing a second run
flock holds a file lock while a command runs, so a second copy of the script waits for it or exits at once.
9 minflock -nflock -wflock -
date — date and time in the shell
The date command: current time, output formats, timestamps for files and logs, date arithmetic.
4 mindatedate -ddate -Iseconds -
Locale and encoding
Language, encoding and formats — LANG/LC_*, generating locales, UTF-8 problems.
4 minlocalelocale -alocale-gen -
bash — the command shell
A command interpreter for interactive input, builtins, and shell scripts.
5 minbash --versionhelptype pwd -
chage — password and account expiry
Reads and changes local password aging settings and an account expiration date.
4 minchage -lgetent passwdpasswd -S -
hash — Bash command path cache
A Bash builtin for inspecting and clearing remembered paths to external commands.
4 mintype hashhelp hashhash -
hostname — machine names and resolution
Reads or temporarily sets the host name; selected options report FQDNs and addresses.
4 minhostnamehostname -shostname -f -
nologin — a shell that refuses login
A login-shell replacement that reports refusal and exits instead of opening an interactive shell.
4 mingetent passwdid labsvctype -a -
pwd — the working directory
The Bash builtin prints the logical or physical path of the current directory.
3 minpwdpwd -Lpwd -P -
sleep — delay execution
Pauses execution for a specified duration; does not test whether another program is ready.
4 minsleepsleep --help -
uname — kernel and system information
Reports kernel identity, node name, and machine architecture, not the distribution release.
3 minuname -suname -runame -v -
wait — wait for a child task in Bash
A Bash builtin that waits for a child task and returns its completion status.
4 mintype waithelp waitsleep -
whoami — identify the effective user
whoami prints the user name tied to the process's effective user ID — the account you act as now.
3 minwhoamiid -uid -un