Learning

Every command our lessons run

Commands

The Linux commands a working engineer reaches for: every one our lessons ask you to type, and the important ones no lesson teaches yet. Each card gives the forms worth knowing, who is allowed to run it, and how to get the same answer on a Mac — with a line for Windows. Open a command for the details, and follow a link to the lesson that explains it.

Every one of these is an ordinary program running in user mode, or a builtin the shell runs itself; none runs inside the kernel. When a command needs the kernel it asks through a system call, and the kernel checks whether the caller may. Who can run it says how that check goes: any user, only root (the administrator account, user id 0) or a process holding the one Linux capability that grants that power, or root only for some of its forms.

Processes and scheduling

List, signal, prioritise and pin the programs running on a machine.

  1. Any userShell builtinLinux: Built inmacOS: Built inWindows: No equivalent

    bg — background

    Lets a stopped job carry on running in the background.

    Forms, platforms and lessons

    Common forms

    bg
    Continue the most recent stopped job in the background.

    Who can run it · Any user

    The shell sends SIGCONT to its own child process group, which needs no privilege.

    On each platform

    Linux Built in
    A builtin of bash, zsh and every POSIX shell.
    macOS Built in
    A builtin of zsh and bash.
    Windows No equivalent
    No equivalent; see fg.

    Taught in

  2. Needs rootLinux: Built inmacOS: No equivalentWindows: Different tool

    chrt

    Runs a program, or changes a running one, under a real-time scheduling policy such as SCHED_FIFO, which runs ahead of every ordinary process.

    Forms, platforms and lessons

    Common forms

    chrt -f 50 program
    Run under SCHED_FIFO at real-time priority 50.
    chrt -p PID
    Show a process’s policy and priority.

    Who can run it · Needs root

    Real-time policies can starve the rest of the machine, so the kernel asks for root or CAP_SYS_NICE (or a raised RLIMIT_RTPRIO limit) before granting one. Showing a policy needs nothing.

    On each platform

    Linux Built in
    From util-linux.
    macOS No equivalent
    No equivalent. taskpolicy moves a process between Apple’s quality-of-service tiers, which is not real-time scheduling.
    Windows Different tool
    start /realtime program starts a program in the real-time priority class.

    Taught in

  3. Any userShell builtinLinux: Built inmacOS: Built inWindows: No equivalent

    fg — foreground

    Brings a stopped or background job back to the foreground of the terminal.

    Forms, platforms and lessons

    Common forms

    fg
    Resume the most recent job in the foreground.
    fg %2
    Resume job number 2.

    Who can run it · Any user

    The shell does this itself, by moving the terminal’s foreground process group and sending SIGCONT to its own children.

    On each platform

    Linux Built in
    A builtin of bash, zsh and every POSIX shell.
    macOS Built in
    A builtin of zsh and bash.
    Windows No equivalent
    No equivalent: cmd and PowerShell have no job control of this kind. PowerShell’s Start-Job runs work in a separate background process instead.

    Taught in

  4. Any userLinux: Install itmacOS: Install itWindows: No equivalent

    htop

    A friendlier top: per-CPU bars, scrolling, a tree view, and keys to search, filter, renice and kill.

    Forms, platforms and lessons

    Common forms

    htop
    The live view; F5 toggles the process tree.

    Who can run it · Any user

    Like top, it reads /proc; its kill and renice keys follow the usual rules.

    On each platform

    Linux Install it
    The htop package.
    macOS Install it
    Homebrew’s htop.
    Windows No equivalent
    No equivalent; Task Manager is the nearest.

    Taught in

    Not yet taught in a lesson.

  5. Some forms need rootLinux: Built inmacOS: Different toolWindows: No equivalent

    ionice — I/O nice

    Sets a process’s I/O scheduling class and priority, so a backup or scan does not starve interactive disk use.

    Forms, platforms and lessons

    Common forms

    ionice -c3 tar czf backup.tgz dir
    Run in the idle class: disk time only when no one else wants it.

    Who can run it · Some forms need root

    Lowering your own I/O priority is allowed; the real-time class, or another user’s process, needs root.

    On each platform

    Linux Built in
    From util-linux; it takes effect under I/O schedulers that honour priorities.
    macOS Different tool
    taskpolicy -d throttle program sets a program’s disk I/O policy.
    Windows No equivalent
    No equivalent.

    Taught in

    Not yet taught in a lesson.

  6. Some forms need rootShell builtinLinux: Built inmacOS: Built inWindows: Different tool

    kill

    Sends a signal to a process: by default a polite request to terminate, or with -9 an order the process cannot catch.

    Forms, platforms and lessons

    Common forms

    kill PID
    Send SIGTERM, asking the process to clean up and exit.
    kill -9 PID
    Send SIGKILL, which the kernel carries out without asking the process.
    kill -- -PGID
    Signal every process in a process group (the minus sign names a group).

    Who can run it · Some forms need root

    The kernel lets you signal processes running as your own user. Signalling someone else’s needs root, or the CAP_KILL capability.

    On each platform

    Linux Built in
    A shell builtin in bash and zsh, and a program in util-linux.
    macOS Built in
    A shell builtin in zsh and bash, and /bin/kill.
    Windows Different tool
    Windows has no Unix signals. taskkill /pid N ends a process (add /f to force it), and Stop-Process -Id N does the same in PowerShell.

    Taught in

  7. Some forms need rootLinux: Built inmacOS: Built inWindows: Different tool

    nice

    Starts a program with a lower (or higher) scheduling priority, expressed as a nice value from −20, most favoured, to 19, least.

    Forms, platforms and lessons

    Common forms

    nice -n 10 make
    Run make ten steps “nicer”, so other work gets the CPU first.

    Who can run it · Some forms need root

    Anyone may make their own work nicer. A negative value, which takes CPU from others, needs root or the CAP_SYS_NICE capability.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The same command and range.
    Windows Different tool
    start /belownormal program starts a program at a lower priority class. Windows has six classes (low, below normal, normal, above normal, high, realtime) rather than nice values.

    Taught in

  8. Any userLinux: Built inmacOS: Built inWindows: No equivalent

    nohup — no hangup

    Runs a command immune to the hangup signal, so it keeps going after you close the terminal.

    Forms, platforms and lessons

    Common forms

    nohup make -j4 &
    Run make in the background, ignoring hangups; output goes to nohup.out.

    Who can run it · Any user

    Ignoring a signal is your own process’s choice, and the kernel needs no permission for it.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The same command.
    Windows No equivalent
    No equivalent: Windows has no hangup signal. A job that must outlive the console runs as a scheduled task (schtasks) or a service.

    Taught in

  9. Any userLinux: Install itmacOS: No equivalentWindows: Different tool

    numactl — NUMA control

    Shows a machine’s NUMA layout (which memory is near which CPUs) and runs a program with a chosen memory and CPU placement.

    Forms, platforms and lessons

    Common forms

    numactl --hardware
    List the NUMA nodes, their CPUs and memory, and the distances between them.

    Who can run it · Any user

    Reading the layout and choosing a placement for your own program are ordinary requests the kernel grants to anyone.

    On each platform

    Linux Install it
    The numactl package.
    macOS No equivalent
    No equivalent.
    Windows Different tool
    start /node N program starts a program on NUMA node N.

    Taught in

  10. Some forms need rootLinux: Built inmacOS: Built inWindows: Different tool

    pgrep — process grep

    Also covers pkill

    Finds processes by name or other attributes and prints their IDs; pkill signals them instead.

    Forms, platforms and lessons

    Common forms

    pgrep -a nginx
    IDs and command lines of processes named nginx.
    pkill -HUP nginx
    Send SIGHUP to them, often a “reload your configuration” request.

    Who can run it · Some forms need root

    Finding is open to anyone; pkill follows kill’s rules, so another user’s processes need root.

    On each platform

    Linux Built in
    From procps-ng.
    macOS Built in
    The same commands.
    Windows Different tool
    tasklist /fi "imagename eq x.exe" and taskkill /im x.exe.

    Taught in

    Not yet taught in a lesson.

  11. Any userLinux: Built inmacOS: Built inWindows: Different tool

    ps — process status

    A snapshot of the processes running now: their IDs, owners, states and the commands that started them.

    Forms, platforms and lessons

    Common forms

    ps
    Your own processes in this terminal.
    ps -e
    Every process on the machine (-e, every).
    ps -ef
    Every process, in full format: owner, parent ID, start time and whole command line.
    ps -e | wc -l
    Count them.

    Who can run it · Any user

    The kernel publishes every process under /proc for any user to read, so anyone can list everything; only a few details of other users’ processes, such as their environment, are withheld.

    On each platform

    Linux Built in
    From procps-ng, in every distribution.
    macOS Built in
    The BSD ps; -e and -f work, though the columns differ from Linux’s.
    Windows Different tool
    tasklist lists processes, and PowerShell’s Get-Process returns them as objects you can sort and filter.

    Taught in

  12. Any userLinux: Built inmacOS: Install itWindows: No equivalent

    pstree — process tree

    Draws the processes as a tree of parents and children, so you can see which shell or service started what.

    Forms, platforms and lessons

    Common forms

    pstree -p
    The tree with process IDs.

    Who can run it · Any user

    It reads what the kernel publishes under /proc, which any user may read.

    On each platform

    Linux Built in
    From psmisc, in most installs.
    macOS Install it
    Homebrew’s pstree.
    Windows No equivalent
    No built-in equivalent; Process Explorer (Sysinternals) shows a tree.

    Taught in

    Not yet taught in a lesson.

  13. Some forms need rootLinux: Built inmacOS: Built inWindows: Different tool

    renice

    Changes the nice value of a process that is already running.

    Forms, platforms and lessons

    Common forms

    renice -n 5 -p PID
    Make a running process five steps nicer.

    Who can run it · Some forms need root

    You may make your own processes nicer. Making any process less nice, or touching another user’s process, needs root or CAP_SYS_NICE.

    On each platform

    Linux Built in
    From util-linux.
    macOS Built in
    The same command.
    Windows Different tool
    Task Manager’s Details tab sets a running process’s priority class.

    Taught in

  14. Some forms need rootLinux: Built inmacOS: No equivalentWindows: Different tool

    taskset

    Pins a process to a chosen set of CPUs (its affinity), so the scheduler runs it only there.

    Forms, platforms and lessons

    Common forms

    taskset -c 3 ./server
    Start server allowed to run only on CPU 3.
    taskset -p PID
    Show a running process’s CPU mask.

    Who can run it · Some forms need root

    You may set the affinity of your own processes. Changing another user’s needs root or CAP_SYS_NICE.

    On each platform

    Linux Built in
    From util-linux.
    macOS No equivalent
    No equivalent: macOS offers no command to pin a process to particular cores.
    Windows Different tool
    start /affinity 8 program takes a hexadecimal mask of allowed processors (8 is binary 1000, processor 3).

    Taught in

  15. Any userLinux: Built inmacOS: Built inWindows: Different tool

    top — the processes at the top of CPU use

    A live, refreshing table of the busiest processes, with the CPU split into time in user programs and time in the kernel.

    Forms, platforms and lessons

    Common forms

    top
    The live view; press q to quit.
    top (us, sy)
    The us share is CPU time in user mode, sy time in the kernel on programs’ behalf.

    Who can run it · Any user

    It only reads what the kernel publishes under /proc, which any user may read. Killing or renicing from inside it follows the same rules as kill and renice.

    On each platform

    Linux Built in
    From procps-ng. htop is a friendlier alternative to install.
    macOS Built in
    Apple’s own top: the same idea with different keys and columns; top -o cpu sorts by CPU. Activity Monitor is the graphical version.
    Windows Different tool
    Task Manager is the graphical view. In PowerShell, Get-Process | Sort-Object CPU -Descending gives a one-off ranking.

    Taught in

Performance and tracing

Find where time goes: counters, samples, traces and the kernel’s own log.

  1. Needs rootLinux: Install itmacOS: No equivalentWindows: No equivalent

    bpftool — BPF tool

    Lists and inspects the eBPF programs and maps loaded into the kernel.

    Forms, platforms and lessons

    Common forms

    bpftool prog list
    Every loaded eBPF program, with where it is attached.
    bpftool map list
    Every eBPF map, the kernel-side tables programs share data through.

    Who can run it · Needs root

    Enumerating the kernel’s eBPF objects is a privileged bpf() operation: root, or CAP_SYS_ADMIN.

    On each platform

    Linux Install it
    Built from the kernel source; packaged as bpftool or with linux-tools.
    macOS No equivalent
    No equivalent: macOS has no eBPF.
    Windows No equivalent
    No built-in equivalent. WSL (the Windows Subsystem for Linux, which runs a real Linux system inside Windows) runs the Linux tool itself.

    Taught in

  2. Needs rootLinux: Install itmacOS: Different toolWindows: Different tool

    bpftrace

    A small language for tracing: attach a few lines of code to a kernel or program event and print counts, histograms or stacks as it runs.

    Forms, platforms and lessons

    Common forms

    bpftrace -e 'tracepoint:syscalls:sys_enter_openat { printf("%s\n", comm); }'
    Print the name of each program as it opens a file.

    Who can run it · Needs root

    It loads eBPF programs into the kernel, which needs root or the CAP_BPF and CAP_PERFMON capabilities.

    On each platform

    Linux Install it
    The bpftrace package.
    macOS Different tool
    dtrace, whose language inspired bpftrace’s; it needs root and is limited by System Integrity Protection.
    Windows Different tool
    DTrace for Windows, an optional feature to install and enable.

    Taught in

  3. Some forms need rootLinux: Built inmacOS: Built inWindows: Different tool

    dmesg

    Prints the kernel’s own log: hardware found at boot, driver messages, and warnings such as the out-of-memory killer choosing a victim.

    Forms, platforms and lessons

    Common forms

    dmesg
    The whole kernel ring buffer.
    dmesg | grep -i raid
    Only the lines that mention RAID.

    Who can run it · Some forms need root

    Any user may read it unless kernel.dmesg_restrict is set to 1, as many distributions now do; then it needs root or CAP_SYSLOG.

    On each platform

    Linux Built in
    From util-linux.
    macOS Built in
    Present, but must be run as root.
    Windows Different tool
    Event Viewer’s System log, or wevtutil and PowerShell’s Get-WinEvent from the command line.

    Taught in

  4. Any userLinux: Built inmacOS: Different toolWindows: Different tool

    free

    How memory is being used: in use, free, held as page cache and buffers, and how much is available for new work.

    Forms, platforms and lessons

    Common forms

    free -h
    Human-readable sizes; the available column is the one that matters.

    Who can run it · Any user

    It reads /proc/meminfo, which any user may read.

    On each platform

    Linux Built in
    From procps-ng.
    macOS Different tool
    vm_stat prints page counts; top’s PhysMem line and Activity Monitor’s Memory tab summarise them.
    Windows Different tool
    Task Manager’s Performance tab, or Performance Monitor’s Memory counters.

    Taught in

  5. Some forms need rootLinux: Install itmacOS: Different toolWindows: Different tool

    gdb — GNU debugger

    The GNU debugger: stops a program at breakpoints, steps through it, and prints variables, registers and stack traces; also reads core dumps.

    Forms, platforms and lessons

    Common forms

    gdb ./prog
    Debug a program; run, break main, bt for a backtrace.
    gdb -p PID
    Attach to a running process.
    gdb prog core
    Examine a crash after the fact.

    Who can run it · Some forms need root

    Starting a program under it is always allowed; attaching to a running one follows ptrace’s rules, as for strace.

    On each platform

    Linux Install it
    The gdb package.
    macOS Different tool
    lldb, installed with the Xcode Command Line Tools; LLDB documents a command-by-command map from GDB.
    Windows Different tool
    WinDbg, or the Visual Studio debugger.

    Taught in

    Not yet taught in a lesson.

  6. Any userLinux: Install itmacOS: Built inWindows: Different tool

    iostat — input/output statistics

    Per-device disk statistics: requests per second, throughput, average wait and how busy each device is.

    Forms, platforms and lessons

    Common forms

    iostat -x 1
    Extended per-device statistics every second, including utilisation.

    Who can run it · Any user

    The counters come from /proc/diskstats, which any user may read.

    On each platform

    Linux Install it
    The sysstat package.
    macOS Built in
    A BSD iostat with different columns (kilobytes per transfer, transfers per second, megabytes per second) and no -x.
    Windows Different tool
    typeperf or Get-Counter with the PhysicalDisk counters.

    Taught in

  7. Needs rootLinux: Install itmacOS: Built inWindows: Different tool

    iotop

    A top for disk I/O: which processes are reading and writing, and how fast.

    Forms, platforms and lessons

    Common forms

    iotop -o
    Only processes doing I/O now.

    Who can run it · Needs root

    It reads per-task I/O accounting through a kernel interface that needs root, or the CAP_NET_ADMIN capability granted to its binary.

    On each platform

    Linux Install it
    The iotop package.
    macOS Built in
    A DTrace script of the same name, runnable only as root.
    Windows Different tool
    Resource Monitor’s Disk tab.

    Taught in

    Not yet taught in a lesson.

  8. Some forms need rootLinux: Install itmacOS: Different toolWindows: No equivalent

    ltrace — library call trace

    Like strace one level up: prints the shared-library calls a program makes, such as malloc and strlen.

    Forms, platforms and lessons

    Common forms

    ltrace ./prog
    Every library call with its arguments and result.

    Who can run it · Some forms need root

    It uses ptrace, under the same rules as strace.

    On each platform

    Linux Install it
    The ltrace package; not available on every architecture.
    macOS Different tool
    dtrace’s pid provider traces function calls, as root.
    Windows No equivalent
    No equivalent.

    Taught in

    Not yet taught in a lesson.

  9. Any userLinux: Install itmacOS: No equivalentWindows: Different tool

    mpstat

    Per-CPU utilisation at an interval: user, system, I/O wait, interrupts and idle for each core, so one saturated core stands out.

    Forms, platforms and lessons

    Common forms

    mpstat -P ALL 1
    Every CPU, every second.

    Who can run it · Any user

    It reads what the kernel publishes under /proc, which any user may read.

    On each platform

    Linux Install it
    The sysstat package.
    macOS No equivalent
    No equivalent; Activity Monitor’s CPU History window shows per-core load.
    Windows Different tool
    typeperf with the per-processor counters.

    Taught in

    Not yet taught in a lesson.

  10. Some forms need rootLinux: Install itmacOS: Different toolWindows: Different tool

    perf — performance

    Linux’s performance tool: counts hardware events such as cache misses, samples where CPU time goes, and records traces, all through the kernel’s performance-counter interface.

    Forms, platforms and lessons

    Common forms

    perf stat ./prog
    Run a program and print its event counts: cycles, instructions, branch misses.
    perf stat -e cache-references,cache-misses ./prog
    Count only the events you name.
    perf top
    A live ranking of the functions using the CPU, across programs and the kernel.
    perf record -g ./prog
    Sample with call stacks; perf report reads the result.

    Who can run it · Some forms need root

    Measuring your own programs is allowed by default. Watching the whole system or the kernel needs root, the CAP_PERFMON capability, or a lowered kernel.perf_event_paranoid setting.

    On each platform

    Linux Install it
    Ships with the kernel source; distributions package it as perf or linux-tools matched to the running kernel.
    macOS Different tool
    sample profiles one process from the command line; Instruments (and its command-line form xctrace) comes with Xcode.
    Windows Different tool
    Windows Performance Recorder captures CPU samples and events, and Windows Performance Analyzer reads them.

    Taught in

  11. Any userLinux: Install itmacOS: Different toolWindows: Different tool

    pidstat

    Per-process statistics at an interval: CPU, memory, disk, or the voluntary and forced context switches of each process.

    Forms, platforms and lessons

    Common forms

    pidstat -w 1
    Context switches per second for each process: voluntary (it blocked) and non-voluntary (it was preempted).

    Who can run it · Any user

    It reads each process’s counters from /proc, which any user may read.

    On each platform

    Linux Install it
    The sysstat package.
    macOS Different tool
    top -stats pid,command,csw shows each process’s context-switch count (csw).
    Windows Different tool
    typeperf with the Process and Thread counters, which include context switches per second.

    Taught in

  12. Some forms need rootLinux: Built inmacOS: Different toolWindows: Different tool

    pmap — process map

    Prints a process’s memory map: each region’s address, size, permissions and the file it maps.

    Forms, platforms and lessons

    Common forms

    pmap -x PID
    Extended: resident and dirty sizes per region.

    Who can run it · Some forms need root

    Your own processes are open to you; another user’s map needs root, like reading their /proc/PID/maps.

    On each platform

    Linux Built in
    From procps-ng.
    macOS Different tool
    vmmap PID.
    Windows Different tool
    VMMap (Sysinternals).

    Taught in

    Not yet taught in a lesson.

  13. Any userLinux: Install itmacOS: No equivalentWindows: Different tool

    sar — system activity reporter

    The system activity reporter: records CPU, memory, disk and network statistics all day, so you can look back at what happened at 3 a.m.

    Forms, platforms and lessons

    Common forms

    sar -u 1 5
    CPU use, five one-second samples.
    sar -n DEV
    Network interface statistics from today’s history.

    Who can run it · Any user

    It reads what the kernel publishes under /proc, which any user may read.

    On each platform

    Linux Install it
    The sysstat package, with its collection service enabled.
    macOS No equivalent
    No equivalent.
    Windows Different tool
    Performance Monitor data collector sets (logman).

    Taught in

    Not yet taught in a lesson.

  14. Some forms need rootLinux: Install itmacOS: Different toolWindows: Different tool

    strace — system-call trace

    Prints every system call a program makes, with its arguments and result: the most direct view of a program’s conversation with the kernel.

    Forms, platforms and lessons

    Common forms

    strace ls
    Trace one command from start to finish.
    strace -f bash -c 'ls; true'
    Follow child processes too (-f, follow forks).
    strace -c ls
    Count calls and time per call instead of printing each one.
    strace -p PID
    Attach to a running process.

    Who can run it · Some forms need root

    Tracing a program you start is always allowed. Attaching to a running process uses ptrace, which most distributions limit (through the Yama ptrace_scope setting) to your own descendants unless you have root or CAP_SYS_PTRACE.

    On each platform

    Linux Install it
    The strace package; often preinstalled.
    macOS Different tool
    dtruss prints system calls using DTrace; it needs root, and System Integrity Protection stops it tracing Apple’s own programs. fs_usage shows file-system calls.
    Windows Different tool
    Process Monitor (Sysinternals) records file, registry, network and process activity.

    Taught in

  15. Any userShell builtinLinux: Built inmacOS: Built inWindows: Different tool

    time

    Runs a command and reports how long it took: wall-clock time, and CPU time spent in user mode and in the kernel.

    Forms, platforms and lessons

    Common forms

    time cat big.log > /dev/null
    Time one read of a file; real is elapsed, user and sys are CPU.

    Who can run it · Any user

    The shell starts the program and asks the kernel for its child’s resource usage when it ends, which needs no privilege.

    On each platform

    Linux Built in
    A keyword in bash and zsh; GNU /usr/bin/time is a separate program with more detail.
    macOS Built in
    A keyword in zsh and bash, and /usr/bin/time.
    Windows Different tool
    PowerShell’s Measure-Command { … } reports elapsed time. Beware cmd’s time: it shows or sets the system clock.

    Taught in

  16. Any userLinux: Built inmacOS: Built inWindows: No equivalent

    uptime

    How long the machine has been up, how many users are logged in, and the load averages over the last 1, 5 and 15 minutes.

    Forms, platforms and lessons

    Common forms

    uptime
    One line: time, up time, users, load averages.

    Who can run it · Any user

    It reads /proc/loadavg and /proc/uptime, which any user may read.

    On each platform

    Linux Built in
    From procps-ng.
    macOS Built in
    The same command and output.
    Windows No equivalent
    No equivalent: Windows keeps no load average. Performance Monitor (perfmon) charts processor counters live.

    Taught in

  17. Any userLinux: Install itmacOS: No equivalentWindows: No equivalent

    valgrind

    Runs a program on a simulated CPU that checks every memory access: finds leaks, use after free and reads of uninitialised memory; its other tools profile caches and calls.

    Forms, platforms and lessons

    Common forms

    valgrind --leak-check=full ./prog
    Report each leaked allocation with the stack that made it.

    Who can run it · Any user

    It runs your program as an ordinary user process, only much slower.

    On each platform

    Linux Install it
    The valgrind package.
    macOS No equivalent
    Not supported on current macOS (Valgrind lists Intel Macs up to macOS 11); leaks finds leaks, and the compilers’ AddressSanitizer finds bad accesses.
    Windows No equivalent
    No equivalent; compilers’ AddressSanitizer covers much of it.

    Taught in

    Not yet taught in a lesson.

  18. Any userLinux: Built inmacOS: Different toolWindows: Different tool

    vmstat — virtual memory statistics

    One line per interval summarising the whole machine: runnable processes, memory, swapping, block I/O, interrupts, context switches and the CPU split.

    Forms, platforms and lessons

    Common forms

    vmstat 1
    Print a new line every second; the first line is the average since boot.

    Who can run it · Any user

    It reads system-wide counters from /proc, open to any user.

    On each platform

    Linux Built in
    From procps-ng.
    macOS Different tool
    vm_stat shows memory and paging only; top and Activity Monitor give the rest.
    Windows Different tool
    typeperf prints chosen performance counters at an interval, and PowerShell’s Get-Counter returns them.

    Taught in

Files and permissions

Names, inodes, permissions and who holds a file open.

  1. Needs rootLinux: Built inmacOS: Different toolWindows: Different tool

    chattr — change attributes

    Sets ext2/3/4 attribute flags such as immutable (i), which even root cannot write through until it is cleared.

    Forms, platforms and lessons

    Common forms

    chattr +i file
    Make a file immutable.
    chattr +a log
    Allow only appending.

    Who can run it · Needs root

    The immutable and append-only flags need CAP_LINUX_IMMUTABLE, in practice root.

    On each platform

    Linux Built in
    From e2fsprogs.
    macOS Different tool
    chflags uchg file sets the user-immutable flag.
    Windows Different tool
    attrib +r sets read-only, a weaker flag.

    Taught in

    Not yet taught in a lesson.

  2. Some forms need rootLinux: Built inmacOS: Built inWindows: Different tool

    chgrp — change group

    Changes a file’s group.

    Forms, platforms and lessons

    Common forms

    chgrp staff file
    Give the file to group staff.

    Who can run it · Some forms need root

    An owner may move a file to any group they belong to; anything else needs root (CAP_CHOWN).

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The same command.
    Windows Different tool
    icacls.

    Taught in

    Not yet taught in a lesson.

  3. Some forms need rootLinux: Built inmacOS: Built inWindows: Different tool

    chmod — change mode

    Changes a file’s permission bits: read, write and execute for its owner, its group and everyone else, plus the setuid, setgid and sticky bits.

    Forms, platforms and lessons

    Common forms

    chmod 755 file
    Owner may read, write and run; group and others may read and run (octal 7, 5, 5).
    chmod g+rw data.txt
    Add read and write for the group.
    chmod u+s program
    Set the setuid bit: the program runs with its owner’s user ID.

    Who can run it · Some forms need root

    Only a file’s owner may change its mode. Changing anyone else’s file needs root or the CAP_FOWNER capability.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The same modes; chmod +a also edits macOS access control lists.
    Windows Different tool
    Windows files carry access control lists rather than mode bits; icacls shows and edits them.

    Taught in

  4. Needs rootLinux: Built inmacOS: Built inWindows: Different tool

    chown — change owner

    Changes which user (and group) owns a file.

    Forms, platforms and lessons

    Common forms

    chown alice file
    Make alice the owner.
    chown :staff file
    Change only the group.

    Who can run it · Needs root

    Giving a file to another user needs root or CAP_CHOWN; otherwise anyone could hand files to others. An owner may change only the group, and only to a group they belong to.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The same command.
    Windows Different tool
    icacls file /setowner user, or takeown to take ownership yourself; both need an administrator.

    Taught in

  5. Any userLinux: Built inmacOS: Built inWindows: Different tool

    cp — copy

    Copies files, or with -a whole trees with their permissions, owners and times kept.

    Forms, platforms and lessons

    Common forms

    cp report.txt /dev/null
    Copy into the null device: the bytes are read and thrown away.
    cp -a /lower /upper
    Archive copy: recursive, keeping metadata, as an overlay file system’s copy-up does.

    Who can run it · Any user

    The kernel checks ordinary file permissions: you need write and search permission on the directory being changed. Keeping another user as owner (-a run by an ordinary user) silently falls back to you.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The BSD cp; -a works.
    Windows Different tool
    cmd’s copy and robocopy, or PowerShell’s Copy-Item, which also answers to cp on Windows.

    Taught in

  6. Any userLinux: Built inmacOS: Built inWindows: No equivalent

    file

    Guesses what a file holds by reading its first bytes, not its name: an ELF executable, a script, text, an image.

    Forms, platforms and lessons

    Common forms

    file /bin/ls
    Reports, for example, a 64-bit ELF executable, dynamically linked.

    Who can run it · Any user

    It only reads the file, so it needs read permission and nothing else.

    On each platform

    Linux Built in
    From the file package, in most installs.
    macOS Built in
    The same program.
    Windows No equivalent
    No built-in equivalent. WSL (the Windows Subsystem for Linux, which runs a real Linux system inside Windows) runs the Linux tool itself.

    Taught in

  7. Any userLinux: Built inmacOS: Built inWindows: Different tool

    find

    Walks a directory tree and prints (or acts on) the files that match tests: name, type, size, age, owner.

    Forms, platforms and lessons

    Common forms

    find . -name '*.log' -mtime +7
    Logs older than seven days.
    find / -xdev -size +1G
    Files over a gigabyte on this file system only.
    find . -type f -print0 | xargs -0 rm
    Delete what it found, safely with odd file names.

    Who can run it · Any user

    It needs read and search permission on each directory it walks; others are reported as errors.

    On each platform

    Linux Built in
    GNU findutils.
    macOS Built in
    BSD find: the common tests match; the path argument is required.
    Windows Different tool
    Get-ChildItem -Recurse -Filter; cmd’s find searches text instead.

    Taught in

    Not yet taught in a lesson.

  8. Any userLinux: Install itmacOS: No equivalentWindows: No equivalent

    getcap — get capabilities

    Shows the capabilities attached to an executable.

    Forms, platforms and lessons

    Common forms

    getcap /usr/bin/ping
    On some distributions shows cap_net_raw=ep: ping may open raw sockets without root.

    Who can run it · Any user

    Reading a file’s capabilities is reading an extended attribute, open to anyone who can reach the file.

    On each platform

    Linux Install it
    The libcap tools.
    macOS No equivalent
    No equivalent.
    Windows No equivalent
    No equivalent.

    Taught in

  9. Any userLinux: Install itmacOS: Different toolWindows: Different tool

    getfacl — get file access control list

    Shows a file’s POSIX access control list: named users and groups with their own permissions, beyond the three classes of ls -l.

    Forms, platforms and lessons

    Common forms

    getfacl file
    Print the owner, group, named entries and the mask.

    Who can run it · Any user

    Reading an ACL needs only search permission on the path; setting one (setfacl) is, like chmod, for the owner or root.

    On each platform

    Linux Install it
    The acl package; usually present.
    macOS Different tool
    macOS uses a different ACL model: ls -le shows it and chmod +a edits it.
    Windows Different tool
    icacls file or PowerShell’s Get-Acl.

    Taught in

  10. Any userLinux: Built inmacOS: Built inWindows: Different tool

    ln — link

    Makes a second name for a file: a hard link (another directory entry for the same inode), or with -s a symbolic link holding a path.

    Forms, platforms and lessons

    Common forms

    ln target name
    A hard link: both names reach the same inode.
    ln -s target name
    A symbolic link: a small file containing the path target.

    Who can run it · Any user

    The kernel checks ordinary file permissions: you need write and search permission on the directory being changed. Many distributions also refuse a hard link to a file you neither own nor can read and write (fs.protected_hardlinks).

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The same command.
    Windows Different tool
    cmd’s mklink (/h for a hard link), or PowerShell’s New-Item -ItemType HardLink or SymbolicLink. PowerShell’s documentation notes that a symbolic link needs an administrator.

    Taught in

  11. Any userLinux: Built inmacOS: Built inWindows: Different tool

    ls — list

    Lists a directory’s entries; with flags, each file’s type, permissions, link count, owner, size, time and inode number.

    Forms, platforms and lessons

    Common forms

    ls -l
    Long listing: type and permissions, links, owner, group, size, time, name.
    ls -i
    Show each file’s inode number.
    ls -ld /tmp
    Describe the directory itself rather than its contents.
    ls -l /proc/self/fd
    List the open file descriptors of the ls process itself.
    ls -Z
    Show SELinux security labels.

    Who can run it · Any user

    Listing needs read permission on the directory, and -l needs search permission to look each entry up; nothing more.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The BSD ls: -l and -i match; -O shows file flags and -e shows ACLs.
    Windows Different tool
    cmd’s dir, or PowerShell’s Get-ChildItem, which also answers to ls on Windows.

    Taught in

  12. Any userLinux: Built inmacOS: Different toolWindows: Different tool

    lsattr — list attributes

    Lists the file-system-specific attribute flags of a file on ext2/3/4: immutable, append-only, indexed directory and more.

    Forms, platforms and lessons

    Common forms

    lsattr -d dir
    The directory’s own flags; I marks a hashed-tree (indexed) directory.

    Who can run it · Any user

    Reading flags needs read access to the file; setting the immutable or append-only flag (chattr) needs CAP_LINUX_IMMUTABLE.

    On each platform

    Linux Built in
    From e2fsprogs.
    macOS Different tool
    macOS file flags are shown by ls -lO and set by chflags.
    Windows Different tool
    attrib shows and sets read-only, hidden, system and archive attributes.

    Taught in

  13. Some forms need rootLinux: Install itmacOS: Built inWindows: Different tool

    lsof — list open files

    Lists open files and the processes holding them, including deleted files still kept alive by an open descriptor.

    Forms, platforms and lessons

    Common forms

    lsof +L1
    Open files whose link count is below 1: deleted, but still taking space.

    Who can run it · Some forms need root

    Any user sees their own processes’ files; seeing every process’s needs root, because another user’s descriptors are hidden from you.

    On each platform

    Linux Install it
    The lsof package; often present.
    macOS Built in
    The same program.
    Windows Different tool
    Handle (Sysinternals) lists open handles, and Resource Monitor shows them per process.

    Taught in

  14. Any userLinux: Built inmacOS: Built inWindows: Built in

    mkdir — make directory

    Creates a directory. Under /sys/fs/cgroup the same call creates a new control group.

    Forms, platforms and lessons

    Common forms

    mkdir name
    Create one directory.
    mkdir -p a/b/c
    Create the parents as needed.

    Who can run it · Any user

    The kernel checks ordinary file permissions: you need write and search permission on the directory being changed.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The same command.
    Windows Built in
    cmd has mkdir (also md), and PowerShell has a mkdir function.

    Taught in

  15. Any userLinux: Built inmacOS: Built inWindows: Different tool

    mv — move

    Renames or moves a file. Within one file system it only rewrites directory entries; across file systems it copies and deletes.

    Forms, platforms and lessons

    Common forms

    mv a b
    Rename a to b: the inode and its data stay where they are.

    Who can run it · Any user

    The kernel checks ordinary file permissions: you need write and search permission on the directory being changed.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The same command.
    Windows Different tool
    cmd’s move, or PowerShell’s Move-Item, which also answers to mv on Windows.

    Taught in

  16. Any userLinux: Built inmacOS: Built inWindows: Different tool

    rm — remove

    Removes a name from a directory. The file itself is freed only when its last name is gone and no process still has it open.

    Forms, platforms and lessons

    Common forms

    rm big.log
    Unlink the name; a process holding the file open keeps the space in use.

    Who can run it · Any user

    The kernel checks ordinary file permissions: you need write and search permission on the directory being changed. In a sticky directory such as /tmp you may remove only your own files.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The same command.
    Windows Different tool
    cmd’s del, or PowerShell’s Remove-Item, which also answers to rm on Windows.

    Taught in

  17. Any userLinux: Built inmacOS: Built inWindows: Built in

    rmdir — remove directory

    Removes an empty directory.

    Forms, platforms and lessons

    Common forms

    rmdir name
    Fails unless the directory is empty.

    Who can run it · Any user

    The kernel checks ordinary file permissions: you need write and search permission on the directory being changed.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The same command.
    Windows Built in
    cmd has rmdir (also rd).

    Taught in

  18. Needs rootLinux: Install itmacOS: No equivalentWindows: No equivalent

    setcap — set capabilities

    Attaches Linux capabilities to an executable, so it starts with one specific power of root instead of all of them.

    Forms, platforms and lessons

    Common forms

    setcap 'cap_net_bind_service=ep' gallery
    Let gallery bind ports below 1024 without being root.

    Who can run it · Needs root

    Setting capabilities on a file needs root or CAP_SETFCAP; otherwise any user could award themselves powers.

    On each platform

    Linux Install it
    The libcap tools (package libcap2-bin or libcap).
    macOS No equivalent
    No equivalent: macOS has no file capabilities.
    Windows No equivalent
    No equivalent: Windows grants privileges to accounts through security policy, not to program files.

    Taught in

  19. Any userLinux: Built inmacOS: Built inWindows: Different tool

    stat — status

    Prints everything an inode records about a file: size, blocks, inode number, link count, owner, permissions and its three timestamps.

    Forms, platforms and lessons

    Common forms

    stat /etc/hostname
    The full inode view of one file.

    Who can run it · Any user

    It needs only search permission on the directories in the path; the file itself need not be readable.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    A BSD stat with a terser default; stat -x prints the Linux-style layout.
    Windows Different tool
    PowerShell’s Get-Item file | Format-List * shows a file’s attributes and times.

    Taught in

  20. Any userLinux: Built inmacOS: Built inWindows: Different tool

    touch

    Creates an empty file, or updates an existing file’s access and modification times.

    Forms, platforms and lessons

    Common forms

    touch file
    Create it if missing; otherwise set its times to now.

    Who can run it · Any user

    It works on ordinary files and pipes under ordinary permissions.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The same command.
    Windows Different tool
    PowerShell’s New-Item file.

    Taught in

    Not yet taught in a lesson.

Disks and file systems

Devices, mounts, file-system layout and the bytes on disk.

  1. Needs rootLinux: Built inmacOS: Different toolWindows: Different tool

    blockdev — block device

    Queries or sets a block device’s parameters: sector sizes, read-ahead, read-only flag.

    Forms, platforms and lessons

    Common forms

    blockdev --getss /dev/sdX
    The logical sector size, the alignment that direct I/O must respect.

    Who can run it · Needs root

    It opens the device node and issues ioctl calls, which needs root.

    On each platform

    Linux Built in
    From util-linux.
    macOS Different tool
    diskutil info reports a disk’s block size.
    Windows Different tool
    fsutil fsinfo sectorinfo C: reports sector sizes and alignment.

    Taught in

  2. Some forms need rootLinux: Built inmacOS: Built inWindows: No equivalent

    dd

    Copies raw bytes from one file or device to another in blocks of a chosen size.

    Forms, platforms and lessons

    Common forms

    dd if=bigfile of=/dev/null bs=1M
    Read a file in one-megabyte blocks and discard it, to time reading.
    dd if=/dev/sda …
    Read a disk device directly, beneath any file system.

    Who can run it · Some forms need root

    Copying your own files needs nothing; reading or writing a disk device needs root, because only root may open it.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The BSD dd.
    Windows No equivalent
    No built-in equivalent. WSL (the Windows Subsystem for Linux, which runs a real Linux system inside Windows) runs the Linux tool itself.

    Taught in

  3. Any userLinux: Built inmacOS: Built inWindows: Different tool

    df — disk free

    How full each mounted file system is, in blocks or with -i in inodes.

    Forms, platforms and lessons

    Common forms

    df -h
    Size, used and available space per mount, human-readable.
    df -i
    Inodes used and free: a disk can be “full” with bytes to spare.

    Who can run it · Any user

    It asks the kernel for each file system’s totals, which any user may read.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The BSD df; -h and -i work.
    Windows Different tool
    PowerShell’s Get-Volume or Get-PSDrive.

    Taught in

  4. Any userLinux: Built inmacOS: Built inWindows: Different tool

    du — disk usage

    How much space files and directories use, adding up the blocks actually allocated.

    Forms, platforms and lessons

    Common forms

    du -sh dir
    One total for a directory.

    Who can run it · Any user

    It walks the tree, so it needs read and search permission on each directory it counts.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The BSD du.
    Windows Different tool
    Disk Usage (du, Sysinternals).

    Taught in

  5. Needs rootLinux: Built inmacOS: No equivalentWindows: No equivalent

    dumpe2fs — dump ext2 file system

    Prints an ext2/3/4 file system’s superblock and every block group’s layout: where its bitmaps, inode table and free blocks are.

    Forms, platforms and lessons

    Common forms

    dumpe2fs -h /dev/sdX
    The superblock only, including the journal settings.

    Who can run it · Needs root

    It reads the raw device, which needs root.

    On each platform

    Linux Built in
    From e2fsprogs.
    macOS No equivalent
    No equivalent.
    Windows No equivalent
    No equivalent. WSL (the Windows Subsystem for Linux, which runs a real Linux system inside Windows) runs the Linux tool itself.

    Taught in

  6. Needs rootLinux: Built inmacOS: No equivalentWindows: No equivalent

    e2fsck — ext2 file system check

    The ext2/3/4 checker: walks every inode, bitmap and directory and reconciles them.

    Forms, platforms and lessons

    Common forms

    e2fsck -fn /dev/sdX
    Force a full check (-f) but change nothing (-n).

    Who can run it · Needs root

    It opens the raw device, which needs root.

    On each platform

    Linux Built in
    From e2fsprogs.
    macOS No equivalent
    No equivalent: macOS does not support ext4.
    Windows No equivalent
    No equivalent. WSL (the Windows Subsystem for Linux, which runs a real Linux system inside Windows) runs the Linux tool itself.

    Taught in

  7. Any userLinux: Built inmacOS: Different toolWindows: Different tool

    fallocate — file allocate

    Reserves disk space for a file without writing it, so later writes cannot fail for lack of space.

    Forms, platforms and lessons

    Common forms

    fallocate -l 1G file
    Allocate one gigabyte as unwritten extents.

    Who can run it · Any user

    Allocating space in a file you can write is an ordinary request, within your disk quota.

    On each platform

    Linux Built in
    From util-linux.
    macOS Different tool
    mkfile creates a file of a given size, writing zeros (with -n it records the size without allocating).
    Windows Different tool
    fsutil file createnew name length creates a file of a given length.

    Taught in

  8. Needs rootLinux: Built inmacOS: Different toolWindows: Different tool

    fdisk

    Shows and edits a disk’s partition table.

    Forms, platforms and lessons

    Common forms

    fdisk -l
    List every disk and its partitions.

    Who can run it · Needs root

    It reads and writes the raw disk device, which only root may open.

    On each platform

    Linux Built in
    From util-linux.
    macOS Different tool
    diskutil list and diskutil partitionDisk; macOS’s own fdisk edits only old MBR tables.
    Windows Different tool
    diskpart.

    Taught in

    Not yet taught in a lesson.

  9. Any userLinux: Built inmacOS: No equivalentWindows: Different tool

    filefrag — file fragmentation

    Shows how a file is laid out on disk: its extents and how many pieces it is in.

    Forms, platforms and lessons

    Common forms

    filefrag -v file
    Every extent: logical offset, physical block and length.

    Who can run it · Any user

    It asks the file system for the file’s map through an ioctl, allowed to anyone who can read the file.

    On each platform

    Linux Built in
    From e2fsprogs.
    macOS No equivalent
    No equivalent.
    Windows Different tool
    Contig (Sysinternals) reports how many fragments a file is in.

    Taught in

  10. Any userLinux: Built inmacOS: Different toolWindows: Different tool

    findmnt — find mount

    Shows the mount table as a tree: which file system is mounted where, with its options and propagation.

    Forms, platforms and lessons

    Common forms

    findmnt
    Every mount, nested under its parent.

    Who can run it · Any user

    It reads /proc/self/mountinfo, which any process may read.

    On each platform

    Linux Built in
    From util-linux.
    macOS Different tool
    mount with no arguments lists mounts.
    Windows Different tool
    mountvol lists volumes and their mount points; Get-Volume describes them.

    Taught in

  11. Any userLinux: Install itmacOS: Install itWindows: Install it

    fio — flexible I/O tester

    A flexible I/O benchmark: describes a workload (random or sequential, block size, queue depth, direct or buffered) and measures throughput and latency.

    Forms, platforms and lessons

    Common forms

    fio --name=r --rw=randread --bs=4k --iodepth=32 --direct=1 --size=1G --runtime=30
    Random 4 KiB reads at queue depth 32, bypassing the page cache.

    Who can run it · Any user

    An ordinary program on files you can write; benchmarking a raw device needs root.

    On each platform

    Linux Install it
    The fio package.
    macOS Install it
    Homebrew’s fio.
    Windows Install it
    fio publishes Windows builds.

    Taught in

    Not yet taught in a lesson.

  12. Needs rootLinux: Built inmacOS: Different toolWindows: Different tool

    fsck — file system check

    Checks a file system’s structures for consistency and repairs them, usually on an unmounted file system after a crash.

    Forms, platforms and lessons

    Common forms

    fsck /dev/sdX1
    Check (and offer to repair) one file system.

    Who can run it · Needs root

    It reads and writes the raw device, which only root may open.

    On each platform

    Linux Built in
    From util-linux, calling per-file-system checkers such as e2fsck.
    macOS Different tool
    fsck_apfs, or diskutil verifyVolume and repairVolume.
    Windows Different tool
    chkdsk (with /f to fix), or PowerShell’s Repair-Volume.

    Taught in

  13. Needs rootLinux: Install itmacOS: No equivalentWindows: Different tool

    hdparm

    Gets and sets low-level settings of ATA disks, such as the drive’s own write cache.

    Forms, platforms and lessons

    Common forms

    hdparm -W 0 /dev/sdX
    Turn off the drive’s volatile write cache.

    Who can run it · Needs root

    It sends commands to the drive itself through the device node, which needs root.

    On each platform

    Linux Install it
    The hdparm package.
    macOS No equivalent
    No equivalent.
    Windows Different tool
    Device Manager’s Policies tab for a disk turns its write caching on or off.

    Taught in

  14. Any userLinux: Built inmacOS: Different toolWindows: Different tool

    lsblk — list block devices

    Lists block devices — disks, partitions, RAID and device-mapper volumes — as a tree, with sizes and whether each is a spinning disk.

    Forms, platforms and lessons

    Common forms

    lsblk -d -o NAME,ROTA
    Whole disks only, with ROTA 1 for rotational (spinning) media.

    Who can run it · Any user

    It reads /sys/block, which any user may read.

    On each platform

    Linux Built in
    From util-linux.
    macOS Different tool
    diskutil list.
    Windows Different tool
    PowerShell’s Get-Disk and Get-PhysicalDisk (its MediaType says HDD or SSD), or diskpart’s list disk.

    Taught in

  15. Needs rootLinux: Install itmacOS: Different toolWindows: Different tool

    mdadm

    Creates, monitors and repairs Linux software RAID arrays.

    Forms, platforms and lessons

    Common forms

    mdadm --detail /dev/md0
    An array’s level, members and state.
    cat /proc/mdstat
    Every array and any rebuild in progress.

    Who can run it · Needs root

    It drives the md devices, which only root may open.

    On each platform

    Linux Install it
    The mdadm package.
    macOS Different tool
    diskutil appleRAID manages AppleRAID sets.
    Windows Different tool
    Storage Spaces, or diskpart’s RAID volumes.

    Taught in

    Not yet taught in a lesson.

  16. Needs rootLinux: Built inmacOS: Different toolWindows: Different tool

    mkfs — make file system

    Creates a new, empty file system on a device: superblock, bitmaps, inode table and root directory.

    Forms, platforms and lessons

    Common forms

    mkfs -t ext4 /dev/sdX1
    Format a partition as ext4 (this front end runs mkfs.ext4).

    Who can run it · Needs root

    Writing a raw disk device needs write permission on its /dev node, which only root (or the disk group) has.

    On each platform

    Linux Built in
    From util-linux, calling per-file-system builders such as e2fsprogs’ mkfs.ext4.
    macOS Different tool
    newfs_apfs, or diskutil eraseVolume.
    Windows Different tool
    format, or PowerShell’s Format-Volume.

    Taught in

  17. Needs rootLinux: Built inmacOS: No equivalentWindows: Different tool

    mkswap — make swap

    Prepares a partition or file to be used as swap space.

    Forms, platforms and lessons

    Common forms

    mkswap /swapfile
    Write a swap signature to the file.

    Who can run it · Needs root

    It writes the device or a root-owned file; enabling it afterwards needs CAP_SYS_ADMIN.

    On each platform

    Linux Built in
    From util-linux.
    macOS No equivalent
    No equivalent: macOS creates and manages its swap files itself (dynamic_pager).
    Windows Different tool
    The paging file is configured in System Properties’ virtual-memory settings.

    Taught in

  18. Needs rootLinux: Built inmacOS: Built inWindows: Different tool

    mount

    Attaches a file system to a directory in the tree; with no arguments, lists what is mounted.

    Forms, platforms and lessons

    Common forms

    mount -t ext4 /dev/sdb1 /mnt/usb
    Mount a device’s ext4 file system at /mnt/usb.
    mount --bind a b
    Make the subtree at a appear at b too.
    mount -t overlay …
    Stack layers into one view, as container runtimes do.

    Who can run it · Needs root

    Mounting changes what every process sees, so the kernel requires root or CAP_SYS_ADMIN, except inside your own mount namespace or for entries marked user in /etc/fstab.

    On each platform

    Linux Built in
    From util-linux.
    macOS Built in
    The BSD mount; diskutil mount is the usual way to mount a disk.
    Windows Different tool
    Windows mounts volumes at drive letters or empty folders: mountvol, or Disk Management.

    Taught in

  19. Needs rootLinux: Install itmacOS: Different toolWindows: Different tool

    parted

    A partition editor that also handles GPT tables and resizing, scriptable from the command line.

    Forms, platforms and lessons

    Common forms

    parted -l
    List partition tables.

    Who can run it · Needs root

    The raw disk device needs root.

    On each platform

    Linux Install it
    GNU parted.
    macOS Different tool
    diskutil partitionDisk and resizeVolume.
    Windows Different tool
    diskpart.

    Taught in

    Not yet taught in a lesson.

  20. Any userLinux: Install itmacOS: Built inWindows: Different tool

    rsync — remote sync

    Copies files locally or over the network, sending only what differs from the destination.

    Forms, platforms and lessons

    Common forms

    rsync -a src/ dst/
    Archive copy: recursive, keeping metadata, skipping unchanged files.

    Who can run it · Any user

    Like cp, it works under ordinary file permissions at each end.

    On each platform

    Linux Install it
    The rsync package; often present.
    macOS Built in
    Recent macOS ships openrsync under the name rsync; the original is in Homebrew.
    Windows Different tool
    robocopy mirrors trees and skips unchanged files.

    Taught in

  21. Needs rootLinux: Install itmacOS: Install itWindows: Install it

    smartctl — SMART control

    Reads a drive’s own health records (SMART): reallocated sectors, wear, temperature and error logs.

    Forms, platforms and lessons

    Common forms

    smartctl -a /dev/sda
    Every SMART attribute and log.

    Who can run it · Needs root

    It sends commands straight to the drive, which needs root.

    On each platform

    Linux Install it
    The smartmontools package.
    macOS Install it
    Homebrew’s smartmontools.
    Windows Install it
    smartmontools publishes a Windows build.

    Taught in

    Not yet taught in a lesson.

  22. Some forms need rootLinux: Built inmacOS: No equivalentWindows: Different tool

    swapon — swap on

    Starts using a prepared swap area; with --show, lists the ones in use.

    Forms, platforms and lessons

    Common forms

    swapon /swapfile
    Enable it.
    swapon --show
    List swap areas, their sizes and use.

    Who can run it · Some forms need root

    Listing is open to anyone; enabling or disabling swap needs root or CAP_SYS_ADMIN.

    On each platform

    Linux Built in
    From util-linux.
    macOS No equivalent
    No equivalent; sysctl vm.swapusage shows how much swap is in use.
    Windows Different tool
    Task Manager’s Memory page shows paged memory; the paging file is set in System Properties.

    Taught in

  23. Any userLinux: Built inmacOS: Built inWindows: Different tool

    sync — synchronise

    Asks the kernel to write all dirty cached data to disk now.

    Forms, platforms and lessons

    Common forms

    sync
    Flush every file system’s dirty pages.

    Who can run it · Any user

    Any process may ask the kernel to write back its caches.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The same command.
    Windows Different tool
    Sync (Sysinternals) flushes file-system data to disk.

    Taught in

  24. Any userLinux: Built inmacOS: Built inWindows: Built in

    tar — tape archive

    Bundles files into one archive, or unpacks one, keeping names, permissions and times.

    Forms, platforms and lessons

    Common forms

    tar czf out.tgz dir
    Create (c) a gzip-compressed (z) archive file (f).
    tar xf out.tgz
    Extract it.

    Who can run it · Any user

    It reads and writes ordinary files under ordinary permissions; restoring other users’ ownership needs root.

    On each platform

    Linux Built in
    GNU tar.
    macOS Built in
    bsdtar from libarchive, with the same common flags.
    Windows Built in
    Windows 10 and later include bsdtar as tar, usable from cmd and PowerShell.

    Taught in

  25. Needs rootLinux: Built inmacOS: No equivalentWindows: No equivalent

    tune2fs — tune ext2 file system

    Shows or changes the settings of an ext2/3/4 file system, such as its features and reserved blocks.

    Forms, platforms and lessons

    Common forms

    tune2fs -l /dev/sdX
    List the superblock’s settings.

    Who can run it · Needs root

    It reads and writes the device directly, which needs root.

    On each platform

    Linux Built in
    From e2fsprogs.
    macOS No equivalent
    No equivalent.
    Windows No equivalent
    No equivalent. WSL (the Windows Subsystem for Linux, which runs a real Linux system inside Windows) runs the Linux tool itself.

    Taught in

  26. Needs rootLinux: Built inmacOS: Built inWindows: Different tool

    umount — unmount

    Detaches a mounted file system.

    Forms, platforms and lessons

    Common forms

    umount /mnt/usb
    Unmount; fails while a process still uses it.

    Who can run it · Needs root

    The same rule as mount: root or CAP_SYS_ADMIN.

    On each platform

    Linux Built in
    From util-linux.
    macOS Built in
    The BSD umount, or diskutil unmount.
    Windows Different tool
    mountvol path /d removes a volume’s mount point.

    Taught in

Text and pipelines

Small programs joined by pipes, each doing one thing to a stream of lines.

  1. Any userLinux: Built inmacOS: Built inWindows: No equivalent

    awk — Aho, Weinberger and Kernighan, its authors

    A small language for column-shaped text: splits each line into fields and runs a pattern–action program over them.

    Forms, platforms and lessons

    Common forms

    awk '{print $1}' access.log
    The first field of every line.
    awk '$9 == 500 {n++} END {print n}' access.log
    Count lines whose ninth field is 500.

    Who can run it · Any user

    It works on ordinary files and pipes under ordinary permissions.

    On each platform

    Linux Built in
    gawk or mawk, depending on the distribution.
    macOS Built in
    The BSD “one true awk”.
    Windows No equivalent
    No built-in equivalent; PowerShell splits lines with -split.

    Taught in

    Not yet taught in a lesson.

  2. Any userLinux: Built inmacOS: Built inWindows: Different tool

    base64

    Encodes bytes as Base64 text, or decodes it back.

    Forms, platforms and lessons

    Common forms

    base64 -d token.txt
    Decode.

    Who can run it · Any user

    It works on ordinary files and pipes under ordinary permissions.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The same command (-d decodes).
    Windows Different tool
    certutil -encode and -decode.

    Taught in

    Not yet taught in a lesson.

  3. Any userLinux: Built inmacOS: Built inWindows: Different tool

    cat — concatenate

    Reads files (or its input) and writes them to its output, one after another; also the quickest way to read a kernel file under /proc or /sys.

    Forms, platforms and lessons

    Common forms

    cat notes.txt
    Print a file.
    cat /proc/self/maps
    Print the memory map of the cat process itself.
    cat log | grep err | wc -l
    Feed a file into a pipeline.

    Who can run it · Any user

    It reads and writes ordinary files and pipes under ordinary permissions; the kernel asks nothing more.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The BSD cat; macOS has no /proc, so the kernel files it reads on Linux do not exist.
    Windows Different tool
    cmd’s type, or PowerShell’s Get-Content, which also answers to cat on Windows.

    Taught in

  4. Any userLinux: Built inmacOS: Built inWindows: Different tool

    cut

    Prints selected fields or character positions from each line.

    Forms, platforms and lessons

    Common forms

    cut -d: -f1 /etc/passwd
    The first colon-separated field: every user name.

    Who can run it · Any user

    It works on ordinary files and pipes under ordinary permissions.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The same command.
    Windows Different tool
    PowerShell’s -split operator.

    Taught in

    Not yet taught in a lesson.

  5. Any userLinux: Built inmacOS: Built inWindows: Different tool

    diff — difference

    Shows how two files differ, line by line; -u prints the unified format that patches and code reviews use.

    Forms, platforms and lessons

    Common forms

    diff -u old new
    A unified diff.

    Who can run it · Any user

    It works on ordinary files and pipes under ordinary permissions.

    On each platform

    Linux Built in
    GNU diffutils.
    macOS Built in
    The same program.
    Windows Different tool
    fc, or PowerShell’s Compare-Object.

    Taught in

    Not yet taught in a lesson.

  6. Any userShell builtinLinux: Built inmacOS: Built inWindows: Built in

    echo

    Writes its arguments to its output.

    Forms, platforms and lessons

    Common forms

    echo hello > out.txt
    The shell opens out.txt for echo’s output before it runs.

    Who can run it · Any user

    It reads and writes ordinary files and pipes under ordinary permissions; the kernel asks nothing more.

    On each platform

    Linux Built in
    A shell builtin, and /bin/echo in coreutils.
    macOS Built in
    A builtin of zsh and bash.
    Windows Built in
    cmd has echo; PowerShell’s is Write-Output.

    Taught in

  7. Any userLinux: Built inmacOS: Built inWindows: Different tool

    grep — global regular expression print (from the ed command g/re/p)

    Prints the lines that match a pattern.

    Forms, platforms and lessons

    Common forms

    grep error log
    Lines containing error.
    grep -F word file
    Match fixed strings, not regular expressions.
    grep -r TODO .
    Search a whole tree.
    grep -i -c x
    Ignore case; print only the count.

    Who can run it · Any user

    It reads and writes ordinary files and pipes under ordinary permissions; the kernel asks nothing more.

    On each platform

    Linux Built in
    GNU grep.
    macOS Built in
    The BSD-derived grep; the common flags match.
    Windows Different tool
    findstr, or PowerShell’s Select-String.

    Taught in

  8. Any userLinux: Built inmacOS: Built inWindows: Different tool

    hexdump

    The util-linux hex dumper; hexdump -C gives the familiar offset, hex and text columns.

    Forms, platforms and lessons

    Common forms

    hexdump -C file
    Canonical hex plus ASCII view.

    Who can run it · Any user

    It works on ordinary files and pipes under ordinary permissions.

    On each platform

    Linux Built in
    From util-linux.
    macOS Built in
    The BSD hexdump, same -C.
    Windows Different tool
    Format-Hex.

    Taught in

    Not yet taught in a lesson.

  9. Any userLinux: Built inmacOS: Built inWindows: Different tool

    less

    Shows long output one screen at a time, scrolling both ways and searching with /.

    Forms, platforms and lessons

    Common forms

    cat big.log | grep error | less
    Page through a pipeline’s output.

    Who can run it · Any user

    It reads and writes ordinary files and pipes under ordinary permissions; the kernel asks nothing more.

    On each platform

    Linux Built in
    From the less package, in every distribution.
    macOS Built in
    The same program.
    Windows Different tool
    more, or PowerShell’s Out-Host -Paging.

    Taught in

  10. Any userLinux: Built inmacOS: Built inWindows: Built in

    more

    The older pager: shows output a screen at a time, forwards only.

    Forms, platforms and lessons

    Common forms

    more file
    Press space for the next screen.

    Who can run it · Any user

    It reads and writes ordinary files and pipes under ordinary permissions; the kernel asks nothing more.

    On each platform

    Linux Built in
    From util-linux.
    macOS Built in
    On macOS more is less in a compatibility mode.
    Windows Built in
    cmd has more.

    Taught in

  11. Any userLinux: Built inmacOS: Built inWindows: Different tool

    sed — stream editor

    A stream editor: applies editing commands, most often a substitution, to each line as it passes.

    Forms, platforms and lessons

    Common forms

    sed 's/old/new/g' file
    Replace every old with new on each line.
    sed -i 's/a/b/' file
    Edit the file in place (GNU form).

    Who can run it · Any user

    It reads and writes ordinary files and pipes under ordinary permissions; the kernel asks nothing more.

    On each platform

    Linux Built in
    GNU sed.
    macOS Built in
    BSD sed: in-place editing needs an explicit (possibly empty) suffix, sed -i '' ….
    Windows Different tool
    PowerShell’s -replace operator.

    Taught in

  12. Any userLinux: Built inmacOS: Different toolWindows: Different tool

    sha256sum

    Computes a file’s SHA-256 digest, to check that a download is exactly what was published.

    Forms, platforms and lessons

    Common forms

    sha256sum file
    Print the digest.
    sha256sum -c SHA256SUMS
    Check files against a list of digests.

    Who can run it · Any user

    It works on ordinary files and pipes under ordinary permissions.

    On each platform

    Linux Built in
    From coreutils.
    macOS Different tool
    shasum -a 256 file.
    Windows Different tool
    PowerShell’s Get-FileHash (SHA-256 by default).

    Taught in

    Not yet taught in a lesson.

  13. Any userLinux: Built inmacOS: Built inWindows: Built in

    sort

    Sorts lines; can also merge already-sorted files.

    Forms, platforms and lessons

    Common forms

    sort file
    Sort lines.
    sort -m a b
    Merge two sorted files in one pass.
    sort | uniq -c
    Sort so that equal lines sit together, then count them.

    Who can run it · Any user

    It reads and writes ordinary files and pipes under ordinary permissions; the kernel asks nothing more.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The BSD sort.
    Windows Built in
    cmd has a simpler sort (/r reverses); PowerShell’s Sort-Object sorts objects.

    Taught in

  14. Any userLinux: Install itmacOS: Built inWindows: Different tool

    strings

    Prints the runs of printable characters inside a binary: error messages, paths, version strings.

    Forms, platforms and lessons

    Common forms

    strings prog | grep -i version
    Find version text in an executable.

    Who can run it · Any user

    It works on ordinary files and pipes under ordinary permissions.

    On each platform

    Linux Install it
    GNU binutils.
    macOS Built in
    The same purpose, from the developer tools.
    Windows Different tool
    Strings (Sysinternals).

    Taught in

    Not yet taught in a lesson.

  15. Any userLinux: Built inmacOS: Built inWindows: Different tool

    tail

    Prints the last lines of a file; with -f, keeps printing as the file grows.

    Forms, platforms and lessons

    Common forms

    tail -n 50 log
    The last fifty lines.
    tail -f log
    Follow the file as lines are appended.

    Who can run it · Any user

    It reads and writes ordinary files and pipes under ordinary permissions; the kernel asks nothing more.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The same command.
    Windows Different tool
    PowerShell’s Get-Content -Tail 50, with -Wait to follow.

    Taught in

  16. Any userLinux: Built inmacOS: Built inWindows: Different tool

    tee

    Copies its input to its output and to files at once, like a T-junction in a pipe.

    Forms, platforms and lessons

    Common forms

    make 2>&1 | tee build.log
    Watch a build and keep a log.

    Who can run it · Any user

    It works on ordinary files and pipes under ordinary permissions.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The same command.
    Windows Different tool
    PowerShell’s Tee-Object.

    Taught in

    Not yet taught in a lesson.

  17. Any userLinux: Built inmacOS: Built inWindows: No equivalent

    tr — translate

    Translates or deletes characters as they stream past.

    Forms, platforms and lessons

    Common forms

    tr a-z A-Z
    Upper-case everything.
    tr -d '\r'
    Delete carriage returns (Windows line endings).

    Who can run it · Any user

    It works on ordinary files and pipes under ordinary permissions.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The same command.
    Windows No equivalent
    No equivalent; PowerShell’s -replace does the job.

    Taught in

    Not yet taught in a lesson.

  18. Any userLinux: Built inmacOS: Built inWindows: Different tool

    uniq — unique

    Drops (or counts) repeated adjacent lines, so it is almost always run after sort.

    Forms, platforms and lessons

    Common forms

    uniq -c
    Prefix each distinct line with how many times it repeated.

    Who can run it · Any user

    It reads and writes ordinary files and pipes under ordinary permissions; the kernel asks nothing more.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The same command.
    Windows Different tool
    PowerShell’s Get-Unique (also on sorted input), or Group-Object for counts.

    Taught in

  19. Any userLinux: Built inmacOS: Built inWindows: Different tool

    wc — word count

    Counts lines, words and bytes.

    Forms, platforms and lessons

    Common forms

    wc -l
    Count lines only.
    ps -e | wc -l
    Count processes.

    Who can run it · Any user

    It reads and writes ordinary files and pipes under ordinary permissions; the kernel asks nothing more.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The same command.
    Windows Different tool
    PowerShell’s Measure-Object -Line.

    Taught in

  20. Any userLinux: Built inmacOS: Built inWindows: Different tool

    xargs

    Turns lines of input into arguments for another command, running it once or in batches.

    Forms, platforms and lessons

    Common forms

    find . -name '*.o' | xargs rm
    Delete every object file found.
    xargs -P4 -n1 cmd
    Up to four cmd processes at once, one argument each.

    Who can run it · Any user

    It works on ordinary files and pipes under ordinary permissions.

    On each platform

    Linux Built in
    GNU findutils.
    macOS Built in
    The BSD xargs.
    Windows Different tool
    PowerShell’s ForEach-Object.

    Taught in

    Not yet taught in a lesson.

  21. Any userLinux: Install itmacOS: Built inWindows: Different tool

    xxd

    Prints a file as hexadecimal and text side by side, or turns such a dump back into bytes.

    Forms, platforms and lessons

    Common forms

    xxd file | head
    The first bytes in hex: magic numbers, headers, byte order.

    Who can run it · Any user

    It works on ordinary files and pipes under ordinary permissions.

    On each platform

    Linux Install it
    Ships with vim, usually present.
    macOS Built in
    The same program.
    Windows Different tool
    PowerShell’s Format-Hex.

    Taught in

    Not yet taught in a lesson.

  22. Any userLinux: Built inmacOS: Built inWindows: No equivalent

    yes

    Prints a line (default y) forever: a quick way to answer prompts, or to make a writer that never stops.

    Forms, platforms and lessons

    Common forms

    yes | head
    A pipeline whose writer is stopped by SIGPIPE.

    Who can run it · Any user

    It reads and writes ordinary files and pipes under ordinary permissions; the kernel asks nothing more.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The same command.
    Windows No equivalent
    No equivalent.

    Taught in

Building and inspecting programs

Compile, link, disassemble and look inside executables and runtimes.

  1. Any userLinux: Install itmacOS: Install itWindows: Different tool

    cc — C compiler

    The traditional name for “the system’s C compiler”; on Linux it usually runs gcc, on macOS clang.

    Forms, platforms and lessons

    Common forms

    cc -Wall -o pipeline pipeline.c
    Compile with all common warnings into pipeline.

    Who can run it · Any user

    Compiling, linking and reading program files are ordinary file reads and writes; the kernel asks nothing more.

    On each platform

    Linux Install it
    A link to gcc or clang once one is installed.
    macOS Install it
    Apple clang, with the Xcode Command Line Tools (xcode-select --install).
    Windows Different tool
    The Microsoft compiler is cl.

    Taught in

  2. Any userLinux: Install itmacOS: Install itWindows: Install it

    clang

    The LLVM C and C++ compiler, flag-compatible with gcc for everyday use, and able to target other machines (here RISC-V) from one install.

    Forms, platforms and lessons

    Common forms

    clang --target=riscv64-linux-gnu -O2 -S f.c
    Compile for 64-bit RISC-V and stop at assembly.

    Who can run it · Any user

    Compiling, linking and reading program files are ordinary file reads and writes; the kernel asks nothing more.

    On each platform

    Linux Install it
    The clang package.
    macOS Install it
    Apple’s clang is the system compiler, installed with the Xcode Command Line Tools (xcode-select --install).
    Windows Install it
    LLVM’s Windows installer, or as a component of Visual Studio.

    Taught in

  3. Any userLinux: Install itmacOS: Install itWindows: Install it

    gcc — GNU Compiler Collection

    The GNU C compiler: turns C source into assembly, object files and finally a linked executable, driving the assembler and linker for you.

    Forms, platforms and lessons

    Common forms

    gcc -c main.c
    Compile to an object file, main.o, without linking.
    gcc add3.c -o add3
    Compile and link into the executable add3.
    gcc -S -O2 f.c
    Stop after compiling to assembly, f.s, optimised.

    Who can run it · Any user

    Compiling, linking and reading program files are ordinary file reads and writes; the kernel asks nothing more.

    On each platform

    Linux Install it
    The gcc package (with build-essential on Debian and Ubuntu).
    macOS Install it
    Installed with the Xcode Command Line Tools (xcode-select --install), gcc is really Apple’s clang under that name; real GCC comes from Homebrew.
    Windows Install it
    GCC for Windows comes from MinGW-w64, for example through MSYS2.

    Taught in

  4. Any userLinux: Install itmacOS: Install itWindows: Install it

    git

    Version control: records snapshots of a tree and the history between them.

    Forms, platforms and lessons

    Common forms

    git bisect
    Binary-search the history for the commit that introduced a bug.
    git log --since="12 months ago" --name-only --pretty=format:
    List the files each commit of the last year touched, one name per line, with no commit headers: the raw material for counting how often each file changes.
    git commit
    Record a snapshot.

    Who can run it · Any user

    Reading and writing a repository's files and its history is ordinary file access; the kernel asks nothing more.

    On each platform

    Linux Install it
    The git package.
    macOS Install it
    Installed with the Xcode Command Line Tools (xcode-select --install).
    Windows Install it
    Git for Windows.

    Taught in

  5. Any userLinux: Install itmacOS: Install itWindows: Install it

    go

    The Go toolchain: builds, tests and runs Go programs, with switches that expose the compiler’s decisions.

    Forms, platforms and lessons

    Common forms

    go build -gcflags='-m'
    Print the compiler’s escape-analysis decisions: which values move to the heap.
    go build -race
    Build with the data-race detector.
    go test -race
    Run tests under the race detector.

    Who can run it · Any user

    Compiling, linking and reading program files are ordinary file reads and writes; the kernel asks nothing more.

    On each platform

    Linux Install it
    From go.dev or the distribution.
    macOS Install it
    From go.dev or Homebrew.
    Windows Install it
    From go.dev.

    Taught in

  6. Any userLinux: Install itmacOS: Install itWindows: Install it

    java

    Also covers javac, jcmd, jmap, jstack

    The Java launcher, with the JDK tools beside it: javac compiles to bytecode, and jcmd, jmap and jstack inspect a running JVM.

    Forms, platforms and lessons

    Common forms

    javac Main.java
    Compile to Main.class bytecode.
    jcmd PID Thread.print
    Ask a running JVM for every thread’s stack.
    jmap -histo:live PID
    A histogram of live objects by class.
    jstack PID
    Print the JVM’s thread stacks.

    Who can run it · Any user

    Compiling, linking and reading program files are ordinary file reads and writes; the kernel asks nothing more.

    On each platform

    Linux Install it
    A JDK package such as OpenJDK.
    macOS Install it
    A JDK installer or Homebrew; /usr/bin/java is a stub until one is installed.
    Windows Install it
    A JDK installer.

    Taught in

  7. Any userLinux: Built inmacOS: Different toolWindows: No equivalent

    ld.so

    The dynamic linker: the program the kernel starts first for a dynamically linked executable, which loads its libraries and binds its symbols before main runs.

    Forms, platforms and lessons

    Common forms

    LD_PRELOAD=lib.so prog
    Ask the dynamic linker to load lib.so first, so its symbols win.

    Who can run it · Any user

    It runs inside your own process. For setuid programs it switches to secure-execution mode, ignoring LD_LIBRARY_PATH and restricting LD_PRELOAD, so they cannot be hijacked.

    On each platform

    Linux Built in
    Part of glibc, usually as /lib64/ld-linux-x86-64.so.2.
    macOS Different tool
    dyld, controlled by DYLD_* variables.
    Windows No equivalent
    No command: the Windows loader is part of the system.

    Taught in

  8. Some forms need rootLinux: Built inmacOS: No equivalentWindows: No equivalent

    ldconfig

    Rebuilds the cache the dynamic linker searches for libraries, after libraries are installed.

    Forms, platforms and lessons

    Common forms

    ldconfig -p
    Print the current cache.

    Who can run it · Some forms need root

    Printing the cache is open to all; rebuilding it writes /etc/ld.so.cache, which needs root.

    On each platform

    Linux Built in
    Part of glibc.
    macOS No equivalent
    No equivalent: dyld keeps its own shared cache.
    Windows No equivalent
    No equivalent.

    Taught in

  9. Any userLinux: Built inmacOS: Different toolWindows: Different tool

    ldd

    Lists the shared libraries a program needs and where the dynamic linker would find each one.

    Forms, platforms and lessons

    Common forms

    ldd /bin/ls
    Each library and the path it resolves to.

    Who can run it · Any user

    It runs the dynamic linker in a listing mode, so never point it at a program you do not trust.

    On each platform

    Linux Built in
    Part of glibc.
    macOS Different tool
    otool -L prog.
    Windows Different tool
    dumpbin /dependents prog.exe.

    Taught in

  10. Any userLinux: Install itmacOS: Install itWindows: Install it

    llvm-objdump

    LLVM’s version of objdump, which can disassemble any architecture LLVM supports, such as RISC-V on an x86 or ARM laptop.

    Forms, platforms and lessons

    Common forms

    llvm-objdump -d f.o
    Disassemble, whatever the target architecture.

    Who can run it · Any user

    Compiling, linking and reading program files are ordinary file reads and writes; the kernel asks nothing more.

    On each platform

    Linux Install it
    The llvm package.
    macOS Install it
    Installed with the Xcode Command Line Tools (xcode-select --install) as objdump; the full LLVM tools are in Homebrew.
    Windows Install it
    LLVM’s Windows installer.

    Taught in

  11. Any userLinux: Install itmacOS: Install itWindows: Different tool

    make

    Rebuilds only what is out of date, following the rules and dependencies in a Makefile; -j runs independent steps in parallel.

    Forms, platforms and lessons

    Common forms

    make
    Build the default target.
    make -j4
    Run up to four jobs at once.

    Who can run it · Any user

    Compiling, linking and reading program files are ordinary file reads and writes; the kernel asks nothing more.

    On each platform

    Linux Install it
    GNU make, with the build tools.
    macOS Install it
    GNU make 3.81, with the Xcode Command Line Tools (xcode-select --install).
    Windows Different tool
    Visual Studio’s nmake, a make for Microsoft’s tools.

    Taught in

  12. Any userLinux: Install itmacOS: Install itWindows: Different tool

    nm — name list

    Lists the symbols in an object file: which functions and variables it defines and which it still needs from elsewhere.

    Forms, platforms and lessons

    Common forms

    nm main.o
    T marks a defined function, U an undefined symbol the linker must resolve.

    Who can run it · Any user

    Compiling, linking and reading program files are ordinary file reads and writes; the kernel asks nothing more.

    On each platform

    Linux Install it
    GNU binutils.
    macOS Install it
    Installed with the Xcode Command Line Tools (xcode-select --install).
    Windows Different tool
    dumpbin /symbols.

    Taught in

  13. Any userLinux: Install itmacOS: No equivalentWindows: Install it

    nvcc — NVIDIA CUDA compiler

    NVIDIA’s CUDA compiler: splits a .cu file into host code and GPU kernels and compiles each.

    Forms, platforms and lessons

    Common forms

    nvcc vec.cu -o vec
    Compile a CUDA program.

    Who can run it · Any user

    Compiling, linking and reading program files are ordinary file reads and writes; the kernel asks nothing more.

    On each platform

    Linux Install it
    The CUDA Toolkit.
    macOS No equivalent
    No equivalent: CUDA 10.2 was the last release to support macOS. Apple GPUs are programmed through Metal.
    Windows Install it
    The CUDA Toolkit.

    Taught in

  14. Any userLinux: Install itmacOS: Install itWindows: Different tool

    objdump — object dump

    Shows what is inside an object file or executable: section headers, symbols, relocations, and with -d the machine code disassembled.

    Forms, platforms and lessons

    Common forms

    objdump -d prog
    Disassemble the code sections.
    objdump -dr main.o
    Disassemble, showing the relocations the linker will fill in.
    objdump -T /bin/zsh
    The dynamic symbol table.

    Who can run it · Any user

    Compiling, linking and reading program files are ordinary file reads and writes; the kernel asks nothing more.

    On each platform

    Linux Install it
    GNU binutils, installed with gcc.
    macOS Install it
    LLVM’s objdump, with the Xcode Command Line Tools (xcode-select --install); otool -tv is Apple’s own disassembler.
    Windows Different tool
    dumpbin /disasm, from Visual Studio.

    Taught in

  15. Any userLinux: Built inmacOS: Install itWindows: Install it

    python3

    Runs Python 3 programs, or an interactive prompt.

    Forms, platforms and lessons

    Common forms

    python3 app.py
    Run a program.

    Who can run it · Any user

    Compiling, linking and reading program files are ordinary file reads and writes; the kernel asks nothing more.

    On each platform

    Linux Built in
    Present on most distributions.
    macOS Install it
    /usr/bin/python3 prompts to install the Command Line Tools; python.org and Homebrew provide others.
    Windows Install it
    From python.org or the Microsoft Store.

    Taught in

  16. Any userLinux: Install itmacOS: Different toolWindows: Different tool

    readelf — read ELF

    Prints the structure of an ELF file, Linux’s executable format: its header, program headers (what to load where) and section headers.

    Forms, platforms and lessons

    Common forms

    readelf -h prog
    The ELF header.
    readelf -l prog
    Program headers: the segments the loader maps.
    readelf -n /bin/ls
    Notes, such as the control-flow-protection properties.

    Who can run it · Any user

    Compiling, linking and reading program files are ordinary file reads and writes; the kernel asks nothing more.

    On each platform

    Linux Install it
    GNU binutils.
    macOS Different tool
    macOS executables are Mach-O, not ELF; otool -l prints their load commands.
    Windows Different tool
    Windows executables are PE files; dumpbin /headers prints theirs.

    Taught in

  17. Any userLinux: Install itmacOS: Install itWindows: Install it

    rustc

    Also covers cargo

    The Rust compiler; projects usually drive it through cargo, Rust’s build tool and package manager.

    Forms, platforms and lessons

    Common forms

    rustc main.rs
    Compile one file.
    cargo update
    Update dependencies to their newest allowed versions.

    Who can run it · Any user

    Compiling, linking and reading program files are ordinary file reads and writes; the kernel asks nothing more.

    On each platform

    Linux Install it
    Through rustup.
    macOS Install it
    Through rustup.
    Windows Install it
    Through rustup.

    Taught in

  18. Any userLinux: Built inmacOS: No equivalentWindows: No equivalent

    setarch — set architecture

    Runs a program with a changed execution domain, most usefully with address-space layout randomisation turned off.

    Forms, platforms and lessons

    Common forms

    setarch -R ./show
    Run with ASLR off (-R), so addresses repeat from run to run.

    Who can run it · Any user

    Changing the execution domain of a program you start is an ordinary request through personality().

    On each platform

    Linux Built in
    From util-linux.
    macOS No equivalent
    No equivalent.
    Windows No equivalent
    No equivalent.

    Taught in

Kernel and hardware

What kernel is running, which modules it loaded, and the hardware it found.

  1. Needs rootLinux: Install itmacOS: Different toolWindows: Different tool

    dmidecode — DMI decode

    Decodes the firmware’s description of the hardware: maker, model, serial number, memory slots and BIOS version.

    Forms, platforms and lessons

    Common forms

    dmidecode -t memory
    The installed memory modules.

    Who can run it · Needs root

    The firmware tables it reads are readable only by root.

    On each platform

    Linux Install it
    The dmidecode package.
    macOS Different tool
    system_profiler SPHardwareDataType.
    Windows Different tool
    msinfo32, or Get-CimInstance.

    Taught in

    Not yet taught in a lesson.

  2. Needs rootLinux: Built inmacOS: Different toolWindows: No equivalent

    insmod — insert module

    Inserts one module file into the kernel, with no dependency handling.

    Forms, platforms and lessons

    Common forms

    insmod hello.ko
    Load the module built in this directory.

    Who can run it · Needs root

    Root or CAP_SYS_MODULE, as for modprobe.

    On each platform

    Linux Built in
    From kmod.
    macOS Different tool
    kmutil load -p path.
    Windows No equivalent
    No direct equivalent.

    Taught in

  3. Any userLinux: Built inmacOS: Different toolWindows: Different tool

    lscpu — list CPU

    Summarises the processors: architecture, cores, threads per core, sockets, NUMA nodes and cache sizes.

    Forms, platforms and lessons

    Common forms

    lscpu
    The summary.
    lscpu -e
    One line per logical CPU, with its core, socket and node.

    Who can run it · Any user

    It only reads what the kernel publishes under /proc or /sys, which any user may read.

    On each platform

    Linux Built in
    From util-linux.
    macOS Different tool
    sysctl hw and sysctl machdep.cpu.
    Windows Different tool
    Coreinfo (Sysinternals).

    Taught in

  4. Any userLinux: Built inmacOS: Different toolWindows: Different tool

    lsmod — list modules

    Lists the kernel modules loaded right now, their sizes and which other modules use them.

    Forms, platforms and lessons

    Common forms

    lsmod
    One line per loaded module.

    Who can run it · Any user

    It only reads what the kernel publishes under /proc or /sys, which any user may read. (here /proc/modules).

    On each platform

    Linux Built in
    From kmod.
    macOS Different tool
    kmutil showloaded lists loaded kernel extensions.
    Windows Different tool
    driverquery lists installed drivers.

    Taught in

  5. Some forms need rootLinux: Built inmacOS: Different toolWindows: Different tool

    lspci — list PCI

    Lists the devices on the PCI and PCI Express buses; -vv adds their capabilities, such as MSI interrupts and link speed.

    Forms, platforms and lessons

    Common forms

    lspci
    One line per device.
    lspci -vv
    Everything, including capabilities.

    Who can run it · Some forms need root

    Any user sees the device list, but some of each device’s configuration space is readable only by root, so -vv shows more under sudo.

    On each platform

    Linux Built in
    From pciutils.
    macOS Different tool
    system_profiler SPPCIDataType, or ioreg for the full device tree.
    Windows Different tool
    Device Manager, or PowerShell’s Get-PnpDevice.

    Taught in

  6. Any userLinux: Install itmacOS: Different toolWindows: Different tool

    lsusb — list USB

    Lists the USB buses and the devices attached to them.

    Forms, platforms and lessons

    Common forms

    lsusb -t
    As a tree of hubs and ports.

    Who can run it · Any user

    It only reads what the kernel publishes under /proc or /sys, which any user may read.

    On each platform

    Linux Install it
    The usbutils package; often present.
    macOS Different tool
    system_profiler SPUSBHostDataType.
    Windows Different tool
    Device Manager, or Get-PnpDevice.

    Taught in

    Not yet taught in a lesson.

  7. Needs rootLinux: Built inmacOS: Different toolWindows: Different tool

    modprobe — module probe

    Loads a kernel module by name, loading the modules it depends on first; -r removes one.

    Forms, platforms and lessons

    Common forms

    modprobe e1000e
    Load a network driver and its dependencies.
    modprobe -r e1000e
    Unload it.

    Who can run it · Needs root

    Adding code to the running kernel is the most powerful thing a process can do, so it needs root or CAP_SYS_MODULE.

    On each platform

    Linux Built in
    From kmod.
    macOS Different tool
    kmutil load, as root, for extensions Apple’s security settings allow.
    Windows Different tool
    pnputil /add-driver … /install installs a driver package, as an administrator.

    Taught in

  8. Any userLinux: Built inmacOS: Different toolWindows: Different tool

    nproc — number of processors

    Prints how many processors this process may use: the logical CPUs, after any affinity or container limit.

    Forms, platforms and lessons

    Common forms

    nproc
    A number; build tools pass it to make -j.

    Who can run it · Any user

    It asks the kernel for its own CPU affinity mask.

    On each platform

    Linux Built in
    From coreutils.
    macOS Different tool
    sysctl -n hw.ncpu; Homebrew’s coreutils adds nproc.
    Windows Different tool
    The NUMBER_OF_PROCESSORS environment variable.

    Taught in

  9. Needs rootLinux: Built inmacOS: Different toolWindows: Different tool

    rmmod — remove module

    Removes a loaded module, if nothing is using it.

    Forms, platforms and lessons

    Common forms

    rmmod e1000e
    Unload a driver.

    Who can run it · Needs root

    Root or CAP_SYS_MODULE.

    On each platform

    Linux Built in
    From kmod.
    macOS Different tool
    kmutil unload.
    Windows Different tool
    pnputil /delete-driver removes a driver package.

    Taught in

  10. Some forms need rootLinux: Built inmacOS: Built inWindows: No equivalent

    sysctl — system control

    Reads and sets kernel tunables, the files under /proc/sys.

    Forms, platforms and lessons

    Common forms

    sysctl vm.dirty_ratio
    Read one setting.
    sysctl -w vm.dirty_ratio=10
    Change it until the next reboot.

    Who can run it · Some forms need root

    Reading most settings is open to anyone; writing one needs root.

    On each platform

    Linux Built in
    From procps-ng.
    macOS Built in
    The BSD sysctl, with different names (hw.ncpu, vm.swapusage).
    Windows No equivalent
    No single equivalent.

    Taught in

  11. Any userLinux: Built inmacOS: Built inWindows: Different tool

    uname

    Prints the kernel’s name, release, version and the machine’s architecture.

    Forms, platforms and lessons

    Common forms

    uname -a
    Everything on one line.
    uname -r
    The kernel release, such as 6.8.0-45-generic.
    uname -v
    The build string, which says whether the kernel is preemptible (PREEMPT).

    Who can run it · Any user

    Any process may ask the kernel who it is.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    Reports the Darwin kernel; sw_vers gives the macOS version.
    Windows Different tool
    ver, or systeminfo for more.

    Taught in

Networking

Interfaces, sockets, routes, packets and firewall rules.

  1. Any userLinux: Built inmacOS: Built inWindows: Built in

    curl

    Sends one request to a URL and prints the response: the everyday tool for testing HTTP APIs.

    Forms, platforms and lessons

    Common forms

    curl -i https://example.com
    Show the response headers too.
    curl -X POST -d @body.json -H 'Content-Type: application/json' URL
    Send a JSON body.
    curl -w '%{time_total}\n' -o /dev/null -s URL
    Time a request.

    Who can run it · Any user

    Ordinary client sockets.

    On each platform

    Linux Built in
    Present on most distributions.
    macOS Built in
    The same program.
    Windows Built in
    Windows 10 and later include curl.exe.

    Taught in

    Not yet taught in a lesson.

  2. Any userLinux: Install itmacOS: Built inWindows: Different tool

    dig

    Asks DNS servers a question and prints the full answer: records, their time-to-live, and which server replied.

    Forms, platforms and lessons

    Common forms

    dig example.com
    The A records.
    dig +trace example.com
    Follow the delegation from the root servers down.

    Who can run it · Any user

    Ordinary UDP and TCP queries.

    On each platform

    Linux Install it
    BIND’s utilities (bind9-dnsutils or bind-utils).
    macOS Built in
    The same program.
    Windows Different tool
    nslookup, or PowerShell’s Resolve-DnsName.

    Taught in

    Not yet taught in a lesson.

  3. Some forms need rootLinux: Install itmacOS: No equivalentWindows: Different tool

    ethtool — Ethernet tool

    Queries and tunes a network card’s driver: link speed, offloads, ring sizes and per-queue counters.

    Forms, platforms and lessons

    Common forms

    ethtool -S eth0
    The driver’s own statistics, including drops per queue.

    Who can run it · Some forms need root

    Reading is mostly open to anyone; changing settings needs root or CAP_NET_ADMIN.

    On each platform

    Linux Install it
    The ethtool package; often present.
    macOS No equivalent
    No equivalent; ifconfig and networksetup -getMedia show the link.
    Windows Different tool
    Get-NetAdapterStatistics.

    Taught in

  4. Some forms need rootLinux: Built inmacOS: Built inWindows: Built in

    hostname

    Prints, or sets, the machine’s host name, which a UTS namespace can make different per container.

    Forms, platforms and lessons

    Common forms

    hostname
    Print it.
    hostname web1
    Set it, inside a new UTS namespace or as root.

    Who can run it · Some forms need root

    Printing is open to anyone; setting it needs root or CAP_SYS_ADMIN in the UTS namespace.

    On each platform

    Linux Built in
    From hostname or net-tools; hostnamectl sets it permanently on systemd.
    macOS Built in
    The same command; scutil --set HostName sets it permanently.
    Windows Built in
    hostname prints it.

    Taught in

  5. Some forms need rootLinux: Built inmacOS: Different toolWindows: Different tool

    ip

    Shows and changes network interfaces, addresses, routes and network namespaces.

    Forms, platforms and lessons

    Common forms

    ip addr
    Interfaces and their addresses.
    ip route
    The routing table.
    ip netns add web
    Create a network namespace named web.
    ip netns exec web ip link set lo up
    Run a command inside it.

    Who can run it · Some forms need root

    Showing is open to anyone; changing interfaces, routes or namespaces needs root or CAP_NET_ADMIN.

    On each platform

    Linux Built in
    From iproute2; it replaced ifconfig and route.
    macOS Different tool
    ifconfig, route, netstat -rn and networksetup.
    Windows Different tool
    ipconfig, route print, or Get-NetIPAddress.

    Taught in

  6. Any userLinux: Install itmacOS: Install itWindows: Install it

    iperf

    Measures the throughput between two machines: one runs a server, the other sends to it as fast as the path allows.

    Forms, platforms and lessons

    Common forms

    iperf3 -s
    Run the server.
    iperf3 -c host
    Measure to it for ten seconds.

    Who can run it · Any user

    Ordinary TCP or UDP sockets on an unprivileged port.

    On each platform

    Linux Install it
    The iperf3 package.
    macOS Install it
    Homebrew’s iperf3.
    Windows Install it
    Windows builds of iperf3 are published by third parties.

    Taught in

  7. Needs rootLinux: Built inmacOS: Different toolWindows: Different tool

    iptables — IP tables

    Edits the kernel’s packet-filter rules: which packets to accept, drop or rewrite.

    Forms, platforms and lessons

    Common forms

    iptables -L -n -v
    List rules with packet counts.

    Who can run it · Needs root

    Changing (and on most systems even listing) firewall rules needs root or CAP_NET_ADMIN.

    On each platform

    Linux Built in
    From iptables; on current distributions it is a front end to nftables.
    macOS Different tool
    pfctl controls macOS’s packet filter, pf.
    Windows Different tool
    New-NetFirewallRule and Windows Defender Firewall.

    Taught in

  8. Any userLinux: Install itmacOS: Install itWindows: Different tool

    mtr

    Combines traceroute and ping: keeps probing every hop and shows loss and latency per hop live.

    Forms, platforms and lessons

    Common forms

    mtr example.com
    The live view; mtr -r -c 100 prints a report instead.

    Who can run it · Any user

    Its helper, mtr-packet, needs raw sockets, so it is installed setuid root (or with CAP_NET_RAW) and ordinary users can run mtr.

    On each platform

    Linux Install it
    The mtr package.
    macOS Install it
    Homebrew’s mtr, run with sudo.
    Windows Different tool
    pathping.

    Taught in

    Not yet taught in a lesson.

  9. Any userLinux: Built inmacOS: Built inWindows: Different tool

    nc — netcat

    Netcat: opens a raw TCP or UDP connection, or listens for one, and pipes it to your terminal.

    Forms, platforms and lessons

    Common forms

    nc -zv host 5432
    Is anything listening on port 5432?
    nc -l 9000
    Listen and print whatever arrives.

    Who can run it · Any user

    Ordinary sockets; listening below port 1024 needs root or CAP_NET_BIND_SERVICE.

    On each platform

    Linux Built in
    An OpenBSD or Nmap variant is present on most distributions; their flags differ slightly.
    macOS Built in
    The same program.
    Windows Different tool
    PowerShell’s Test-NetConnection host -Port 5432 checks a port.

    Taught in

    Not yet taught in a lesson.

  10. Any userLinux: Install itmacOS: Built inWindows: Built in

    netstat — network statistics

    The older tool for sockets, routes and protocol counters; -s prints per-protocol statistics.

    Forms, platforms and lessons

    Common forms

    netstat -s
    Counters per protocol: drops, retransmits, errors.

    Who can run it · Any user

    It reads /proc/net, which any user may read.

    On each platform

    Linux Install it
    The net-tools package; deprecated in favour of ss and ip.
    macOS Built in
    The BSD netstat.
    Windows Built in
    netstat ships with Windows.

    Taught in

  11. Needs rootLinux: Built inmacOS: Different toolWindows: Different tool

    nft — netfilter tables

    The nftables front end: the current Linux firewall, which replaces iptables with one rule language for every protocol.

    Forms, platforms and lessons

    Common forms

    nft list ruleset
    Print every table, chain and rule.

    Who can run it · Needs root

    Root or CAP_NET_ADMIN, as for iptables.

    On each platform

    Linux Built in
    The nftables package, standard on current distributions.
    macOS Different tool
    pfctl.
    Windows Different tool
    Windows Defender Firewall.

    Taught in

    Not yet taught in a lesson.

  12. Any userLinux: Built inmacOS: Built inWindows: Install it

    openssl

    A toolkit for keys, certificates and TLS: inspect a server’s certificate chain, make keys, compute hashes.

    Forms, platforms and lessons

    Common forms

    openssl s_client -connect host:443
    Open a TLS connection and print the certificate chain.
    openssl x509 -in cert.pem -noout -text
    Decode a certificate.

    Who can run it · Any user

    Ordinary files and sockets.

    On each platform

    Linux Built in
    OpenSSL, present on most distributions.
    macOS Built in
    /usr/bin/openssl is LibreSSL, a fork; OpenSSL itself is in Homebrew.
    Windows Install it
    Third-party builds; Git for Windows includes one.

    Taught in

    Not yet taught in a lesson.

  13. Any userLinux: Built inmacOS: Built inWindows: Built in

    ping

    Sends ICMP echo requests and reports each reply’s round-trip time, to test whether a host is reachable.

    Forms, platforms and lessons

    Common forms

    ping -c 4 example.com
    Four probes, then a summary.

    Who can run it · Any user

    Modern Linux lets ordinary users send pings through ICMP sockets (net.ipv4.ping_group_range); older systems gave the binary the CAP_NET_RAW capability.

    On each platform

    Linux Built in
    From iputils.
    macOS Built in
    The same command.
    Windows Built in
    ping ships with Windows (-n sets the count).

    Taught in

  14. Any userLinux: Built inmacOS: Built inWindows: Built in

    scp — secure copy

    Copies files to or from another machine over SSH.

    Forms, platforms and lessons

    Common forms

    scp file host:/tmp/
    Copy up.
    scp -r host:dir .
    Copy a directory down.

    Who can run it · Any user

    The same as ssh.

    On each platform

    Linux Built in
    OpenSSH.
    macOS Built in
    OpenSSH.
    Windows Built in
    Included with Windows’s OpenSSH client.

    Taught in

    Not yet taught in a lesson.

  15. Some forms need rootLinux: Built inmacOS: Different toolWindows: Different tool

    ss

    Lists sockets: listening ports, connections and their states, and their queues.

    Forms, platforms and lessons

    Common forms

    ss -ltn
    Listening TCP sockets, numeric.
    ss -tn
    Established TCP connections with their send and receive queues.
    ss -ltnp
    Also the process owning each socket.

    Who can run it · Some forms need root

    Any user sees every socket; which process owns another user’s socket (-p) is shown only to root.

    On each platform

    Linux Built in
    From iproute2; the successor to netstat.
    macOS Different tool
    netstat -an, or lsof -i for owning processes.
    Windows Different tool
    netstat -ano, or Get-NetTCPConnection.

    Taught in

  16. Any userLinux: Built inmacOS: Built inWindows: Built in

    ssh — secure shell

    Logs in to another machine, or runs one command there, over an encrypted, authenticated connection.

    Forms, platforms and lessons

    Common forms

    ssh user@host
    An interactive login.
    ssh -L 5432:db:5432 bastion
    Forward a local port through another machine.

    Who can run it · Any user

    A client program; the server checks your key or password. It refuses a private key file other users can read.

    On each platform

    Linux Built in
    OpenSSH’s client, on nearly every system.
    macOS Built in
    OpenSSH.
    Windows Built in
    OpenSSH’s client is included in Windows 10 and later.

    Taught in

  17. Some forms need rootLinux: Built inmacOS: No equivalentWindows: No equivalent

    tc

    Traffic control: shapes, delays and drops outgoing packets with queueing disciplines.

    Forms, platforms and lessons

    Common forms

    tc qdisc show
    The queueing discipline on each interface.
    tc qdisc add dev eth0 root netem delay 100ms
    Add 100 ms of delay, to test a slow network.

    Who can run it · Some forms need root

    Showing is open to anyone; changing a discipline needs root or CAP_NET_ADMIN.

    On each platform

    Linux Built in
    From iproute2.
    macOS No equivalent
    No command-line equivalent in the base system.
    Windows No equivalent
    No built-in equivalent.

    Taught in

    Not yet taught in a lesson.

  18. Needs rootLinux: Install itmacOS: Built inWindows: Different tool

    tcpdump

    Captures packets on an interface and prints or saves them, filtered by a small expression language.

    Forms, platforms and lessons

    Common forms

    tcpdump -i eth0 port 443
    Print packets to or from port 443.
    tcpdump -w out.pcap
    Save them for Wireshark.

    Who can run it · Needs root

    Capturing needs a raw packet socket, which needs root or CAP_NET_RAW (and CAP_NET_ADMIN for promiscuous mode).

    On each platform

    Linux Install it
    The tcpdump package; often present.
    macOS Built in
    The same program, run as root.
    Windows Different tool
    pktmon, Windows’s built-in packet monitor.

    Taught in

  19. Any userLinux: Install itmacOS: Built inWindows: Different tool

    traceroute

    Lists the routers on the path to a host, by sending probes whose time-to-live runs out one hop further each time.

    Forms, platforms and lessons

    Common forms

    traceroute example.com
    One line per hop with three round-trip times.

    Who can run it · Any user

    The default probes are ordinary UDP packets, which any user may send.

    On each platform

    Linux Install it
    The traceroute package; tracepath is often present instead.
    macOS Built in
    The same command.
    Windows Different tool
    tracert.

    Taught in

  20. Any userLinux: Built inmacOS: Install itWindows: Different tool

    wget

    Downloads files over HTTP, HTTPS or FTP, retrying and resuming as needed.

    Forms, platforms and lessons

    Common forms

    wget URL
    Save the file under its own name.

    Who can run it · Any user

    Ordinary client sockets.

    On each platform

    Linux Built in
    GNU Wget, present on most distributions.
    macOS Install it
    Homebrew’s wget; curl -O does the same.
    Windows Different tool
    curl.exe -O, or PowerShell’s Invoke-WebRequest.

    Taught in

    Not yet taught in a lesson.

  21. Any userLinux: Install itmacOS: Install itWindows: No equivalent

    wrk

    An HTTP load generator: holds many connections open and reports requests per second and latency.

    Forms, platforms and lessons

    Common forms

    wrk -t1 -c50 -d10s http://localhost:8080/
    One thread, fifty connections, ten seconds.

    Who can run it · Any user

    Ordinary client sockets.

    On each platform

    Linux Install it
    Distribution packages or a source build.
    macOS Install it
    Homebrew’s wrk.
    Windows No equivalent
    No equivalent. WSL (the Windows Subsystem for Linux, which runs a real Linux system inside Windows) runs the Linux tool itself.

    Taught in

Services and logs

Start and stop background services, read their logs, and schedule work.

  1. Any userLinux: Built inmacOS: Built inWindows: Different tool

    crontab — cron table

    Edits your table of commands to run on a schedule.

    Forms, platforms and lessons

    Common forms

    crontab -e
    Edit your schedule.
    crontab -l
    Show it.

    Who can run it · Any user

    Each user has their own table; the cron daemon runs each entry as the user who owns it.

    On each platform

    Linux Built in
    From cronie or another cron; systemd timers are the newer alternative.
    macOS Built in
    Present, though on macOS cron’s work has largely moved into launchd.
    Windows Different tool
    schtasks, or Task Scheduler.

    Taught in

    Not yet taught in a lesson.

  2. Some forms need rootLinux: Built inmacOS: Different toolWindows: Different tool

    journalctl — journal control

    Reads the systemd journal: the logs of services and the kernel, filtered by unit, time or priority.

    Forms, platforms and lessons

    Common forms

    journalctl -u nginx
    One service’s log.
    journalctl -k
    Kernel messages, as dmesg shows.
    journalctl -f
    Follow new entries.

    Who can run it · Some forms need root

    It shows the entries the calling user may read: their own, and everything when run as root or as a member of the groups the system grants log access.

    On each platform

    Linux Built in
    From systemd.
    macOS Different tool
    log show and log stream read the unified log.
    Windows Different tool
    Event Viewer, or Get-WinEvent.

    Taught in

    Not yet taught in a lesson.

  3. Some forms need rootLinux: Built inmacOS: Different toolWindows: Different tool

    systemctl — system control

    Controls systemd, the first process on most Linux systems: starts, stops, enables and inspects services.

    Forms, platforms and lessons

    Common forms

    systemctl status nginx
    Is the service running, since when, and its latest log lines.
    systemctl restart nginx
    Restart it.
    systemctl list-units --failed
    Everything that failed.

    Who can run it · Some forms need root

    Anyone may ask about a service; starting, stopping or enabling a system service needs root or an administrator’s approval.

    On each platform

    Linux Built in
    From systemd, on distributions that use it.
    macOS Different tool
    launchctl controls launchd, macOS’s first process.
    Windows Different tool
    sc query, or the Services console.

    Taught in

    Not yet taught in a lesson.

Containers, VMs and users

Namespaces, containers, virtual machines and the user identities they map.

  1. Needs rootLinux: Built inmacOS: Built inWindows: No equivalent

    chroot — change root

    Runs a program with a different directory as its root, /.

    Forms, platforms and lessons

    Common forms

    chroot /srv/jail /bin/sh
    A shell that sees /srv/jail as the whole file system.

    Who can run it · Needs root

    Changing the root directory needs root or CAP_SYS_CHROOT, because it could fool setuid programs.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The same command, as root.
    Windows No equivalent
    No equivalent.

    Taught in

  2. Needs rootLinux: Install itmacOS: Install itWindows: Install it

    docker

    Builds and runs containers: processes in their own namespaces and cgroups, on a layered file system, managed by the Docker daemon.

    Forms, platforms and lessons

    Common forms

    docker run --rm -it ubuntu bash
    Start a shell in a fresh container.
    docker run --cpus=2 --memory=1g img
    Run with cgroup limits.
    docker run -v "$PWD":/app img
    Bind-mount the current directory into the container.

    Who can run it · Needs root

    The command talks to the Docker daemon, which runs as root unless set up in rootless mode, so Docker warns that only trusted users should control it: whoever does can mount any host directory into a container.

    On each platform

    Linux Install it
    Docker Engine from Docker or the distribution.
    macOS Install it
    Docker Desktop runs a small Linux virtual machine, because containers need a Linux kernel.
    Windows Install it
    Docker Desktop, running Linux containers in WSL 2.

    Taught in

  3. Any userLinux: Built inmacOS: Built inWindows: Different tool

    id

    Prints your user ID, group ID and every group you belong to: the identity the kernel checks permissions against.

    Forms, platforms and lessons

    Common forms

    id
    All of it.
    id -u
    Only the numeric user ID (0 is root).

    Who can run it · Any user

    It asks the kernel for the calling process’s own credentials.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The same command.
    Windows Different tool
    whoami /all.

    Taught in

  4. Any userLinux: Install itmacOS: Install itWindows: Install it

    kubectl

    The command-line client for Kubernetes: sends declared objects to the cluster’s API server and reads their state back.

    Forms, platforms and lessons

    Common forms

    kubectl apply -f deployment.yaml
    Declare the desired state.
    kubectl get pods
    What is running.
    kubectl delete namespace ns
    Delete a namespace and, through finalizers, what it owns.

    Who can run it · Any user

    The local machine asks nothing of you; the cluster decides what you may do with its own access rules.

    On each platform

    Linux Install it
    From kubernetes.io or a package.
    macOS Install it
    Homebrew’s kubectl.
    Windows Install it
    From kubernetes.io or winget.

    Taught in

  5. Some forms need rootLinux: Built inmacOS: No equivalentWindows: No equivalent

    lsns — list namespaces

    Lists the namespaces on the system and how many processes are in each.

    Forms, platforms and lessons

    Common forms

    lsns
    One line per namespace.

    Who can run it · Some forms need root

    Any user sees the namespaces of their own processes; root sees them all.

    On each platform

    Linux Built in
    From util-linux.
    macOS No equivalent
    No equivalent.
    Windows No equivalent
    No equivalent.

    Taught in

    Not yet taught in a lesson.

  6. Needs rootLinux: Built inmacOS: No equivalentWindows: No equivalent

    nsenter — namespace enter

    Runs a program inside another process’s namespaces, such as a running container’s.

    Forms, platforms and lessons

    Common forms

    nsenter -t PID -n ss -ltn
    List the listening sockets inside that process’s network namespace.

    Who can run it · Needs root

    Joining another process’s namespaces needs root (CAP_SYS_ADMIN, and permission to inspect that process).

    On each platform

    Linux Built in
    From util-linux.
    macOS No equivalent
    No equivalent.
    Windows No equivalent
    No equivalent.

    Taught in

    Not yet taught in a lesson.

  7. Some forms need rootLinux: Built inmacOS: Built inWindows: Different tool

    passwd — password

    Changes a password. It must write the root-owned password file, so it is a setuid-root program: the classic example of borrowed authority.

    Forms, platforms and lessons

    Common forms

    passwd
    Change your own password.
    ls -l /usr/bin/passwd
    The s in its permissions is the setuid bit.

    Who can run it · Some forms need root

    Any user may change their own password, because the program runs as root and checks who called it; changing another user’s needs root.

    On each platform

    Linux Built in
    From shadow-utils.
    macOS Built in
    The same command.
    Windows Different tool
    net user name * prompts for a new password.

    Taught in

  8. Needs rootLinux: Install itmacOS: No equivalentWindows: No equivalent

    runc

    The low-level runtime that actually creates a container’s namespaces, cgroups and mounts from an OCI bundle; Docker and Kubernetes call it for you.

    Forms, platforms and lessons

    Common forms

    runc run id
    Start the container described by config.json here.

    Who can run it · Needs root

    Creating namespaces and mounts needs root, unless it runs in rootless mode inside a user namespace.

    On each platform

    Linux Install it
    Installed with Docker or containerd.
    macOS No equivalent
    No equivalent: it runs inside Docker Desktop’s Linux virtual machine.
    Windows No equivalent
    No equivalent.

    Taught in

  9. Any userLinux: Built inmacOS: Built inWindows: Different tool

    su — substitute user

    Starts a shell (or runs a command) as another user, after that user’s password.

    Forms, platforms and lessons

    Common forms

    su - alice
    A login shell as alice.

    Who can run it · Any user

    Any user may run it: like passwd, it is setuid root and switches identity only after checking the target’s password.

    On each platform

    Linux Built in
    From util-linux.
    macOS Built in
    The same command.
    Windows Different tool
    runas /user:name cmd.

    Taught in

    Not yet taught in a lesson.

  10. Some forms need rootLinux: Built inmacOS: No equivalentWindows: No equivalent

    unshare

    Runs a program in new namespaces: its own mount table, process IDs, network, host name or user IDs.

    Forms, platforms and lessons

    Common forms

    unshare --mount --propagation private bash
    A shell whose mounts no one else sees.
    unshare --user --map-root-user bash
    Become root inside a new user namespace, as an ordinary user.

    Who can run it · Some forms need root

    A new user namespace is open to any user, and inside it the others become allowed; outside one, new namespaces need root or CAP_SYS_ADMIN.

    On each platform

    Linux Built in
    From util-linux.
    macOS No equivalent
    No equivalent: macOS has no namespaces.
    Windows No equivalent
    No equivalent. WSL (the Windows Subsystem for Linux, which runs a real Linux system inside Windows) runs the Linux tool itself.

    Taught in

  11. Needs rootLinux: Built inmacOS: Different toolWindows: Different tool

    useradd — user add

    Creates a user account: an entry in /etc/passwd, a user ID, a group and usually a home directory.

    Forms, platforms and lessons

    Common forms

    useradd -m alice
    Create alice with a home directory.

    Who can run it · Needs root

    It writes the system’s account files, which only root may change.

    On each platform

    Linux Built in
    From shadow-utils; Debian’s friendlier adduser wraps it.
    macOS Different tool
    sysadminctl -addUser, or dscl.
    Windows Different tool
    net user name /add, or New-LocalUser.

    Taught in

  12. Some forms need rootLinux: Install itmacOS: No equivalentWindows: Different tool

    virsh

    The command-line client for libvirt, which manages KVM virtual machines: start, stop, inspect and migrate them.

    Forms, platforms and lessons

    Common forms

    virsh list --all
    Every defined VM.
    virsh migrate --live vm qemu+ssh://dest/system
    Move a running VM to another host.

    Who can run it · Some forms need root

    System-wide VMs need root or the libvirt group; each user may also run their own session VMs.

    On each platform

    Linux Install it
    The libvirt client package.
    macOS No equivalent
    No standard equivalent: macOS virtual machines run through Apple’s Virtualization framework.
    Windows Different tool
    Hyper-V’s PowerShell module (Move-VM live-migrates).

    Taught in

  13. Any userLinux: Built inmacOS: Built inWindows: Different tool

    who

    Also covers w

    Lists who is logged in, on which terminal and since when; w adds what each is running and the load average.

    Forms, platforms and lessons

    Common forms

    w
    Users, their idle time and current command.

    Who can run it · Any user

    It reads the login records, which any user may read.

    On each platform

    Linux Built in
    who from coreutils, w from procps-ng.
    macOS Built in
    The same commands.
    Windows Different tool
    query user (quser).

    Taught in

    Not yet taught in a lesson.

Shells and help

The programs that read what you type, and the manual that explains the rest.

  1. Any userLinux: Built inmacOS: Built inWindows: No equivalent

    bash — Bourne-again shell

    The Bourne-again shell, the default interactive shell on most Linux systems.

    Forms, platforms and lessons

    Common forms

    bash -c 'ls; true'
    Run a command string and exit.

    Who can run it · Any user

    An ordinary program.

    On each platform

    Linux Built in
    GNU bash.
    macOS Built in
    macOS ships bash 3.2 (newer versions are in Homebrew); zsh is the default for new accounts.
    Windows No equivalent
    No equivalent. WSL (the Windows Subsystem for Linux, which runs a real Linux system inside Windows) runs the Linux tool itself.

    Taught in

  2. Any userLinux: Built inmacOS: Built inWindows: Different tool

    env — environment

    Prints the environment, or runs a program with variables added or removed.

    Forms, platforms and lessons

    Common forms

    env
    Every variable.
    env -i PATH=/bin sh
    Run sh with an empty environment except PATH.

    Who can run it · Any user

    The environment is your own process’s memory.

    On each platform

    Linux Built in
    From coreutils.
    macOS Built in
    The same command.
    Windows Different tool
    set in cmd, or Get-ChildItem Env:.

    Taught in

    Not yet taught in a lesson.

  3. Any userLinux: Built inmacOS: Built inWindows: Different tool

    man — manual

    Shows the manual page for a command, system call or file format; the number picks the section.

    Forms, platforms and lessons

    Common forms

    man ls
    The page for the ls command (section 1).
    man 2 fork
    The fork system call (section 2).
    man -k word
    Search page titles.

    Who can run it · Any user

    It reads documentation files.

    On each platform

    Linux Built in
    man-db, with pages from the man-pages project; minimal container images leave them out.
    macOS Built in
    The same sections, with BSD pages.
    Windows Different tool
    help in cmd, or Get-Help in PowerShell.

    Taught in

  4. Any userLinux: Built inmacOS: Built inWindows: No equivalent

    sh — shell

    The POSIX shell: reads commands, starts a process for each, and wires up pipes and redirections.

    Forms, platforms and lessons

    Common forms

    sh script.sh
    Run a script.
    sh comfile >output
    The shell opens output for the command before running it.

    Who can run it · Any user

    A shell is an ordinary program that starts other programs.

    On each platform

    Linux Built in
    Usually dash (Debian, Ubuntu) or bash.
    macOS Built in
    /bin/sh re-executes as bash, dash or zsh, chosen by a system link.
    Windows No equivalent
    No equivalent: cmd and PowerShell are different languages. WSL (the Windows Subsystem for Linux, which runs a real Linux system inside Windows) runs the Linux tool itself.

    Taught in

  5. Any userLinux: Built inmacOS: Built inWindows: Different tool

    sudo

    Runs one command as root (or another user), if the system’s sudoers policy lets you.

    Forms, platforms and lessons

    Common forms

    sudo perf top
    Run perf top with root’s powers.
    sudo -l
    What you are allowed to run.

    Who can run it · Any user

    Any user may run it, but it grants anything only to users the sudoers file names. It works because it is a setuid-root program that checks the policy first.

    On each platform

    Linux Built in
    From sudo.
    macOS Built in
    The same program; administrators may use it.
    Windows Different tool
    “Run as administrator”; recent Windows 11 builds also offer a sudo command.

    Taught in

  6. Any userLinux: Built inmacOS: Install itWindows: No equivalent

    watch

    Reruns a command every few seconds and shows its output full-screen, highlighting what changed.

    Forms, platforms and lessons

    Common forms

    watch -n 1 -d 'ss -tn'
    Every second, with differences highlighted.

    Who can run it · Any user

    It just runs the command repeatedly.

    On each platform

    Linux Built in
    From procps-ng.
    macOS Install it
    Homebrew’s watch.
    Windows No equivalent
    No equivalent.

    Taught in

    Not yet taught in a lesson.

  7. Any userLinux: Built inmacOS: Built inWindows: Different tool

    which

    Also covers type

    Prints which file would run for a command name, by searching PATH.

    Forms, platforms and lessons

    Common forms

    which python3
    The full path that python3 resolves to.
    type ls
    The shell’s own answer, including aliases and builtins.

    Who can run it · Any user

    It only looks at directories.

    On each platform

    Linux Built in
    A small program; the shell builtins type and command -v are more exact.
    macOS Built in
    A zsh builtin.
    Windows Different tool
    where, or PowerShell’s Get-Command.

    Taught in

    Not yet taught in a lesson.

  8. Any userLinux: Install itmacOS: Built inWindows: No equivalent

    zsh — Z shell

    The Z shell: compatible with sh for scripts, with richer completion and prompts.

    Forms, platforms and lessons

    Common forms

    zsh
    Start one.

    Who can run it · Any user

    An ordinary program.

    On each platform

    Linux Install it
    The zsh package.
    macOS Built in
    The default shell for new macOS accounts.
    Windows No equivalent
    No equivalent.

    Taught in

PostgreSQL programs

The programs that ship with PostgreSQL: the server, its client, and backup, upgrade and repair tools.

  1. Any userLinux: Install itmacOS: Install itWindows: Install it

    initdb

    Creates a new database cluster: the data directory, its system catalogs and the template databases. Settings such as data checksums, encoding and default collation are fixed here.

    Forms, platforms and lessons

    Common forms

    initdb -D datadir
    Create a cluster.
    initdb -D datadir --data-checksums
    With page checksums, which detect corruption.

    Who can run it · Any user

    It works on the data directory’s files, so it must run as the operating-system user that owns them, usually postgres. Not as root: the server refuses to run as root, and so does initdb.

    On each platform

    Linux Install it
    Installed with PostgreSQL’s packages.
    macOS Install it
    Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
    Windows Install it
    Installed with PostgreSQL’s Windows installer.

    Taught in

  2. Any userLinux: Install itmacOS: Install itWindows: Install it

    pg_amcheck

    Checks tables and B-tree indexes for corruption, using the amcheck extension, across a whole database.

    Forms, platforms and lessons

    Common forms

    pg_amcheck -d db --heapallindexed
    Also check that every heap tuple has its index entries.

    Who can run it · Any user

    A client program: the operating system asks nothing special. What it may do inside the database is decided by the PostgreSQL role it connects as. Its checks run as the connected role, which needs permission to use amcheck.

    On each platform

    Linux Install it
    Installed with PostgreSQL’s packages.
    macOS Install it
    Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
    Windows Install it
    Installed with PostgreSQL’s Windows installer.

    Taught in

  3. Any userLinux: Install itmacOS: Install itWindows: Install it

    pg_basebackup

    Takes a physical copy of a running cluster over the replication protocol: the starting point for a standby or a point-in-time recovery.

    Forms, platforms and lessons

    Common forms

    pg_basebackup -D backup -X stream -P
    A full copy, streaming the WAL it needs, with progress.
    pg_basebackup --incremental=manifest -D inc
    Only blocks changed since an earlier backup.

    Who can run it · Any user

    A client program: the operating system asks nothing special. What it may do inside the database is decided by the PostgreSQL role it connects as. The role needs the REPLICATION attribute.

    On each platform

    Linux Install it
    Installed with PostgreSQL’s packages.
    macOS Install it
    Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
    Windows Install it
    Installed with PostgreSQL’s Windows installer.

    Taught in

  4. Any userLinux: Install itmacOS: Install itWindows: Install it

    pg_checksums

    Enables, disables or verifies data-page checksums on a cluster that has been shut down cleanly.

    Forms, platforms and lessons

    Common forms

    pg_checksums --enable -D datadir
    Turn checksums on (rewrites every page).

    Who can run it · Any user

    It works on the data directory’s files, so it must run as the operating-system user that owns them, usually postgres. Not as root: the server refuses to run as root, and so does initdb.

    On each platform

    Linux Install it
    Installed with PostgreSQL’s packages.
    macOS Install it
    Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
    Windows Install it
    Installed with PostgreSQL’s Windows installer.

    Taught in

  5. Any userLinux: Install itmacOS: Install itWindows: Install it

    pg_controldata

    Prints the cluster’s control file: its state, the latest checkpoint’s position, the next transaction ID, and whether checksums are on.

    Forms, platforms and lessons

    Common forms

    pg_controldata -D datadir
    Everything in the control file.

    Who can run it · Any user

    It works on the data directory’s files, so it must run as the operating-system user that owns them, usually postgres. Not as root: the server refuses to run as root, and so does initdb.

    On each platform

    Linux Install it
    Installed with PostgreSQL’s packages.
    macOS Install it
    Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
    Windows Install it
    Installed with PostgreSQL’s Windows installer.

    Taught in

    Not yet taught in a lesson.

  6. Any userLinux: Install itmacOS: Install itWindows: Install it

    pg_ctl — PostgreSQL control

    Starts, stops, reloads and promotes a server running on a data directory.

    Forms, platforms and lessons

    Common forms

    pg_ctl -D datadir start
    Start the server in the background.
    pg_ctl -D datadir stop -m fast
    Stop, disconnecting clients and rolling back their transactions.
    pg_ctl promote -D datadir
    Turn a standby into a primary.

    Who can run it · Any user

    It works on the data directory’s files, so it must run as the operating-system user that owns them, usually postgres. Not as root: the server refuses to run as root, and so does initdb.

    On each platform

    Linux Install it
    Installed with PostgreSQL’s packages.
    macOS Install it
    Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
    Windows Install it
    Installed with PostgreSQL’s Windows installer.

    Taught in

  7. Any userLinux: Install itmacOS: Install itWindows: Install it

    pg_dump

    Exports one database as SQL or an archive, taking a consistent snapshot while the database stays in use.

    Forms, platforms and lessons

    Common forms

    pg_dump -Fc db > db.dump
    Custom-format archive, for pg_restore.
    pg_dump -s db
    Schema only.

    Who can run it · Any user

    A client program: the operating system asks nothing special. What it may do inside the database is decided by the PostgreSQL role it connects as. It needs read access to everything it dumps.

    On each platform

    Linux Install it
    Installed with PostgreSQL’s packages.
    macOS Install it
    Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
    Windows Install it
    Installed with PostgreSQL’s Windows installer.

    Taught in

  8. Any userLinux: Install itmacOS: Install itWindows: Install it

    pg_isready

    Checks whether a server is accepting connections, for scripts and health checks.

    Forms, platforms and lessons

    Common forms

    pg_isready -h host
    Exit status 0 when accepting connections.

    Who can run it · Any user

    A client program: the operating system asks nothing special. What it may do inside the database is decided by the PostgreSQL role it connects as.

    On each platform

    Linux Install it
    Installed with PostgreSQL’s packages.
    macOS Install it
    Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
    Windows Install it
    Installed with PostgreSQL’s Windows installer.

    Taught in

    Not yet taught in a lesson.

  9. Any userLinux: Install itmacOS: Install itWindows: Install it

    pg_receivewal

    Streams the write-ahead log from a server to local files as it is written, for continuous archiving.

    Forms, platforms and lessons

    Common forms

    pg_receivewal -D walarchive --slot=archiver
    Stream into a directory, holding a replication slot.

    Who can run it · Any user

    A client program: the operating system asks nothing special. What it may do inside the database is decided by the PostgreSQL role it connects as. The role needs REPLICATION.

    On each platform

    Linux Install it
    Installed with PostgreSQL’s packages.
    macOS Install it
    Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
    Windows Install it
    Installed with PostgreSQL’s Windows installer.

    Taught in

  10. Any userLinux: Install itmacOS: Install itWindows: Install it

    pg_restore

    Restores a pg_dump archive, optionally in parallel and selectively.

    Forms, platforms and lessons

    Common forms

    pg_restore -j 8 -d db db.dump
    Restore with eight parallel jobs.

    Who can run it · Any user

    A client program: the operating system asks nothing special. What it may do inside the database is decided by the PostgreSQL role it connects as.

    On each platform

    Linux Install it
    Installed with PostgreSQL’s packages.
    macOS Install it
    Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
    Windows Install it
    Installed with PostgreSQL’s Windows installer.

    Taught in

  11. Any userLinux: Install itmacOS: Install itWindows: Install it

    pg_rewind

    Resynchronises a former primary with the new primary after a failover by copying only the blocks that diverged, instead of a whole new base backup.

    Forms, platforms and lessons

    Common forms

    pg_rewind -D datadir --source-server='host=newprimary'
    Rewind this stopped cluster to match the new primary.

    Who can run it · Any user

    It works on the data directory’s files, so it must run as the operating-system user that owns them, usually postgres. Not as root: the server refuses to run as root, and so does initdb. The target needs wal_log_hints or data checksums.

    On each platform

    Linux Install it
    Installed with PostgreSQL’s packages.
    macOS Install it
    Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
    Windows Install it
    Installed with PostgreSQL’s Windows installer.

    Taught in

  12. Any userLinux: Install itmacOS: Install itWindows: Install it

    pg_test_fsync

    Measures how fast this machine can make writes durable with each sync method, to choose wal_sync_method and to catch storage that lies about flushing.

    Forms, platforms and lessons

    Common forms

    pg_test_fsync -f /data/testfile
    Test on the volume that will hold the WAL.

    Who can run it · Any user

    It writes and syncs a test file anywhere you can write.

    On each platform

    Linux Install it
    Installed with PostgreSQL’s packages.
    macOS Install it
    Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
    Windows Install it
    Installed with PostgreSQL’s Windows installer.

    Taught in

  13. Any userLinux: Install itmacOS: Install itWindows: Install it

    pg_upgrade

    Upgrades a cluster to a new major version in place, reusing the data files instead of dumping and reloading them.

    Forms, platforms and lessons

    Common forms

    pg_upgrade -b oldbin -B newbin -d olddata -D newdata --check
    Check compatibility without changing anything.
    pg_upgrade … --link
    Hard-link data files instead of copying: fast, but the old cluster cannot be used afterwards.

    Who can run it · Any user

    It works on the data directory’s files, so it must run as the operating-system user that owns them, usually postgres. Not as root: the server refuses to run as root, and so does initdb.

    On each platform

    Linux Install it
    Installed with PostgreSQL’s packages.
    macOS Install it
    Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
    Windows Install it
    Installed with PostgreSQL’s Windows installer.

    Taught in

  14. Any userLinux: Install itmacOS: Install itWindows: Install it

    pg_waldump — WAL dump

    Decodes write-ahead-log files into readable records, for debugging and for measuring what the log contains.

    Forms, platforms and lessons

    Common forms

    pg_waldump --stats segment
    Counts and sizes per record type, including full-page images.

    Who can run it · Any user

    It reads WAL files, so it needs read access to them, normally as the data directory’s owner.

    On each platform

    Linux Install it
    Installed with PostgreSQL’s packages.
    macOS Install it
    Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
    Windows Install it
    Installed with PostgreSQL’s Windows installer.

    Taught in

  15. Any userLinux: Install itmacOS: Install itWindows: Install it

    pgbench — PostgreSQL benchmark

    Runs a benchmark against PostgreSQL: a built-in TPC-B-like workload or your own scripts, with many clients, reporting transactions per second and latency.

    Forms, platforms and lessons

    Common forms

    pgbench -i -s 50 db
    Create the test tables at scale factor 50.
    pgbench -c 32 -j 8 -T 60 db
    Thirty-two clients for a minute.

    Who can run it · Any user

    A client program: the operating system asks nothing special. What it may do inside the database is decided by the PostgreSQL role it connects as.

    On each platform

    Linux Install it
    Installed with PostgreSQL’s packages.
    macOS Install it
    Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
    Windows Install it
    Installed with PostgreSQL’s Windows installer.

    Taught in

    Not yet taught in a lesson.

  16. Any userLinux: Install itmacOS: Install itWindows: Install it

    postgres

    The database server itself. Normally started for you by a service manager or pg_ctl; run by hand mainly in single-user mode for emergency repair.

    Forms, platforms and lessons

    Common forms

    postgres --single -D datadir db
    Single-user mode, the last resort when the server refuses connections to prevent transaction-ID wraparound.

    Who can run it · Any user

    It works on the data directory’s files, so it must run as the operating-system user that owns them, usually postgres. Not as root: the server refuses to run as root, and so does initdb.

    On each platform

    Linux Install it
    Installed with PostgreSQL’s packages.
    macOS Install it
    Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
    Windows Install it
    Installed with PostgreSQL’s Windows installer.

    Taught in

  17. Any userLinux: Install itmacOS: Install itWindows: Install it

    psql

    PostgreSQL’s interactive terminal: sends SQL to a server and prints the results, with backslash commands for everything else.

    Forms, platforms and lessons

    Common forms

    psql -h host -U user db
    Connect.
    \d table
    Describe a table (inside psql).
    \x
    Toggle expanded, one-column-per-line output.
    \timing
    Print how long each statement took.

    Who can run it · Any user

    A client program: the operating system asks nothing special. What it may do inside the database is decided by the PostgreSQL role it connects as.

    On each platform

    Linux Install it
    Installed with PostgreSQL’s packages.
    macOS Install it
    Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
    Windows Install it
    Installed with PostgreSQL’s Windows installer.

    Taught in

  18. Any userLinux: Install itmacOS: Install itWindows: Install it

    vacuumdb

    Runs VACUUM and ANALYZE across a database or a whole cluster from the shell.

    Forms, platforms and lessons

    Common forms

    vacuumdb --all --analyze-in-stages
    Rebuild planner statistics quickly after an upgrade, coarse first.

    Who can run it · Any user

    A client program: the operating system asks nothing special. What it may do inside the database is decided by the PostgreSQL role it connects as.

    On each platform

    Linux Install it
    Installed with PostgreSQL’s packages.
    macOS Install it
    Installed with PostgreSQL: Homebrew, Postgres.app or the EDB installer.
    Windows Install it
    Installed with PostgreSQL’s Windows installer.

    Taught in