Compendium Scriptorum#
A map of every command you have met and where to find it again — not a list to memorise. Nobody holds all of this in their head; the skill the course keeps returning to is looking things up, and this page is where you look. Your browser’s find (Ctrl/Cmd+F) is the search box; each command links back to the notebook where it was introduced.
Part I
Command |
Job |
Workhorse flags |
Introduced in |
|---|---|---|---|
print a file’s contents straight to the screen. |
-n number every line |
||
change the working directory — move around the tree. |
<dir> go into a directory (by absolute or relative path)~ / cd go to your home directory (bare `cd` does this too).. go up to the parent directory- go back to the previous directory you were in/abs/path go to an absolute location, counted from the root `/` |
||
wipe the visible screen, giving you a clean prompt. |
— |
||
copy a file (or, with -r, a directory). |
-r recursive — copy a directory and everything inside it-i prompt before overwriting an existing file-v verbose — print each file as it is copied |
||
print the current date and time. |
+FORMAT print using a format string — `%F` is the date as `YYYY-MM-DD`, `%T` the time as `HH:MM:SS` |
||
print its arguments back to standard output. |
-n do not add the trailing newline-e interpret backslash escapes such as `\n` (newline) and `\t` (tab) |
||
identify what kind of file something is, before you open it. |
— |
||
show the first lines of a file. |
-n N show the first N lines (default 10)-c N show the first N bytes instead of lines |
||
list the commands you have run, newest last, each with a number. |
-c clear the history list |
||
page through a file one screen at a time — the pager. (Its “flags” are keys you press while it is open.) |
Space / b page down / page up/pattern → n / N search forward, then jump to the next / previous matchg / G jump to the top / the bottomq quit |
||
list directory contents. |
-l long format: permissions, size, owner, timestamp-a include hidden dotfiles-h human-readable sizes (with `-l`)-t sort by modification time, newest first-R recurse into subdirectories |
||
open the full manual page for a command. |
-k word search every manual’s summary line for a keyword (same as `apropos`) — for when you don’t know the command’s name yet |
||
make a new directory. |
-p create parent directories as needed, and do not error if it already exists |
||
move a file — or rename it (same command: renaming is just moving within a directory). |
-i prompt before overwriting an existing file-v verbose — print what was moved |
||
print the working directory: where you currently are in the filesystem. |
— |
||
remove (delete) a file. Permanently. |
-r recursive — delete a directory and everything in it-i prompt before each removal (a good habit)-f force — never prompt, ignore missing files (dangerous; see the admonition) |
||
remove an empty directory — and only an empty one. |
— |
||
show the last lines of a file. |
-n N show the last N lines (default 10)-c N show the last N bytes instead of lines-f follow — keep printing new lines as the file grows (watch a running job’s log live); stop with Ctrl+C |
||
show a few practical, copy-paste examples for a command, skipping the exhaustive manual. |
— |
||
create an empty file, or update an existing file’s timestamp. |
— |
||
show a directory and everything beneath it as an indented tree. |
-L n descend at most n levels (keep deep trees readable)-d show directories only, not files |
||
print the username the shell is running as. |
— |
Part II
Command |
Job |
Workhorse flags |
Introduced in |
|---|---|---|---|
split each line into fields and act on them — print columns, filter by condition, and compute (sum, mean, min/max). The field-aware, can-do-arithmetic tool cut could not be. |
-F C set the field separator to C (the default is any run of whitespace — which is how it beats cut)-v var=val pass a shell value into the program as an awk variable |
||
pick out columns from each line — by delimited field, or by character position. |
-d C use C as the field delimiter (default is TAB)-f N keep field N (or a list/range like `1,3` or `2-4`); use with `-d`-c N keep character positions N instead of fields (e.g. `1-6`) |
||
search a directory tree for files matching criteria — name, type, size, time — and optionally act on each one. |
-name "PAT" / -iname match the filename against a quoted glob (`-iname` ignores case)-type f / -type d match only files / only directories-maxdepth N descend at most N levels deep-size +Nk / -mtime -N by size (larger than N kB) or age (changed within N days)-exec CMD {} + run CMD on the matches — `{}` is each path, `+` batches them into few calls-print / -delete print the matches (the safe default) / delete them (dangerous — see the admonition) |
||
print the lines of a file (or of its input) that match a pattern — literal text, or a regular expression. |
-i match case-insensitively-v invert — print the lines that do NOT match-n prefix each match with its line number-c print only a count of matching lines-r recurse through a directory tree-l print only the names of files that contain a match-o print only the matched part of each line, not the whole line-E / -F `-E` extended regex (the sane quantifiers/grouping); `-F` fixed string (the pattern is taken literally) |
||
edit a stream line by line — substitute, delete, or selectively print — like grep that can also change what it matches. |
-E use Extended regex (the same ERE as `grep -E`); sed otherwise defaults to Basic regex-n suppress the automatic printing of every line; pair with the `p` command to print only what you choose-i / -i.bak edit the file IN PLACE; `-i.bak` keeps a backup of the original first (see the admonition) |
||
order the lines of its input. |
-n numeric order (treat the field as a number, not text)-r reverse the order-k N sort by field N (with `-t` to set the separator)-t C use C as the field separator for `-k`-u drop duplicate lines, keeping one of each |
||
copy what flows in to a file AND pass it straight through, so you can save a mid-pipeline result without breaking the pipeline. |
-a append to the file instead of overwriting it |
||
translate, delete, or squeeze characters in a stream (it reads standard input, so pipe into it). |
SET1 SET2 translate each character of SET1 to the matching one of SET2 (e.g. `’a-z’ ‘A-Z’` upper-cases)-d SET delete every character in SET (e.g. `-d ‘\r’` strips carriage returns)-s SET squeeze runs of a SET character down to one (e.g. `-s ‘ ‘` collapses spaces) |
||
collapse adjacent duplicate lines, and optionally count them. |
-c prefix each line with the number of times it occurred-d print only the lines that were duplicated-u print only the lines that were never repeated |
||
count the lines, words, and bytes of its input. |
-l count lines-w count words-c count bytes |
||
read a list of items on standard input and turn them into arguments for a command — the bridge from a pipeline that produces names to a command that acts on them. |
-0 items are NUL-separated, not whitespace — pair with `find -print0` to survive spaces and newlines in names-n N use at most N items per command line-I {} place each item where `{}` appears, instead of appending it at the end |
Part III
Command |
Job |
Workhorse flags |
Introduced in |
|---|---|---|---|
change a file’s permissions — who may read, write, and execute it. |
+x / u+x / go-w / a+r symbolic: add (`+`) or remove (`-`) a permission for user (`u`) / group (`g`) / others (`o`) / all (`a`) — `+x` is the one you reach for, it makes a file executable755 / 644 / 700 octal: set all three triads at once — `755` = `rwx` for you and `r-x` for everyone else, `644` = read/write for you and read-only for others, `700` = full access for you and nothing for anyone else-R recurse into a directory tree, applying the change to everything inside (powerful — and easy to misfire; see the admonition) |
||
open the nano editor — modeless, with its key shortcuts shown along the bottom of the screen. |
^O write the file out (save) — the `^` means the Ctrl key^X exit (it offers to save first)^W search (“where is”) |
||
print formatted output from a template — the dependable, portable way a script reports its results. |
%s insert a string argument as-is (e.g. a name or a path)%d / %.3f an integer / a float to 3 decimals — `%.Nf` sets the precision, `%-8s` / `%8.3f` set a field width\n / \t a newline / a tab in the template — printf adds NO trailing newline of its own (unlike echo), so you write `\n` yourself |
||
print a sequence of numbers — for counting, and for driving loops and sweeps. |
N print 1 up to N (`seq 5` → 1 2 3 4 5)FIRST LAST count from FIRST to LAST (`seq 2 6` → 2 3 4 5 6)FIRST STEP LAST count in steps of STEP (`seq 0 2 10` → the even numbers)-w equal width: zero-pad so the numbers line up (`seq -w 8 10` → 08 09 10) |
||
measure how long a command takes — real (wall-clock), user, and system time — by prefixing it. |
time CMD run CMD, then report its timing — `real` is the wall-clock time you actually waited fortime { …; } / time pipe | line as a shell keyword it can also time a whole pipeline, group, or loop, not just one program |
||
tell you what a name actually runs — a shell builtin, a function, an alias, or the path to a program — by searching exactly as the shell would. |
-a show ALL matches, not just the first one the shell would use-t print only the kind (`builtin`, `file`, `alias`, `function`) — handy inside scripts |
||
open the Vim editor — the modal editor that is on every cluster, and the one git, crontab, and friends drop you into whether you asked or not. |
<file> open (or create) a file for editing+N <file> open with the cursor already on line N-R <file> open read-only (the `view` command does the same) so you cannot change it by accident |
Part IV
Command |
Job |
Workhorse flags |
Introduced in |
|---|---|---|---|
give a short name to a longer command — typed shorthand for interactive use. |
alias ll='ls -lh' define an alias (keep your favourites in `.bashrc`)alias list every alias currently definedunalias NAME remove an alias |
||
report free and used space on the mounted filesystems — how full the disk (or your cluster quota) is. |
-h human-readable sizesdf -h . show the filesystem holding the current directory |
||
report how much disk space files and directories use — for finding what is filling your quota. |
-s summary: one total per argument, not every file within-h human-readable sizes (K, M, G)-sh * the everyday combo: a readable total for each item here |
||
promote a shell variable to an ENVIRONMENT variable, so every child process and script inherits it. |
export NAME=value set a variable AND mark it for inheritance, in one stepexport NAME mark an already-set variable for inheritance-p list every exported variable currently in the environment |
||
compress a single file in place (and gunzip to restore it) — the compression behind tar’s -z. |
file compress to `file.gz`, removing the original-d / gunzip decompress (`gunzip file.gz` is the same as `gzip -d`)-k keep the original alongside the compressed copy-9 / -1 best compression (slow) / fastest (less compression) |
||
send a signal to a process — most often to stop one — by its PID. |
kill PID politely ask it to terminate (SIGTERM — it can clean up first)kill -9 PID force-kill (SIGKILL — immediate, no cleanup; the last resort)kill %1 refer to a background job by its `jobs` number instead of its PID |
||
create a link — most usefully a symbolic link, a lightweight pointer from one path to another. |
-s target link create a SYMBOLIC link named `link` pointing at `target`-sf force — replace an existing link of that name |
||
load and unload software on a cluster — adding a chosen version of a tool to your environment on demand. |
module avail list the software (and versions) available to loadmodule load NAME/VER add a module to your environment (puts it on `PATH`, sets its variables)module list show what you currently have loadedmodule purge unload everything — back to a clean environmentmodule swap A B / module unload NAME replace one module with another / drop a single one |
||
run a command immune to hangups, so it keeps going after you log out. |
nohup CMD & run CMD in the background, ignoring the `SIGHUP` sent at logout |
||
print the environment — the exported variables the shell passes down to its children. |
printenv list the whole environment, one `NAME=value` per lineprintenv NAME print just one variable’s value (empty, non-zero exit, if it is unset) |
||
take a snapshot of the processes running right now — what is alive, with their PIDs. |
aux ALL processes for all users, with CPU/memory (the common BSD-style form)-ef the same idea in System-V style; pipe into `grep` to find one-p PID show just one process by PID |
||
sync files and directories — locally or over ssh — copying only what has changed. The workhorse for moving data on and off a cluster. |
-a archive mode: recurse and preserve permissions, times, and symlinks (the everyday default)-v / --progress verbose / show a progress bar on large transfers-z compress data in transit (helps over a slow link)--dry-run show what WOULD transfer, changing NOTHING — run this first--delete delete files on the destination that are gone from the source (dangerous — see the admonition) |
||
report accounting/history for jobs that have run — their state and exit code. |
sacct your recent jobs and how they ended (`COMPLETED`, `FAILED`, `CANCELLED`, `TIMEOUT`)-j JOBID one job by id |
||
submit a batch script to the scheduler — it queues the job and prints a job ID. |
sbatch script.sh queue the script; it runs later on a compute node, its output going to `slurm-<jobid>.out`--array=1-N submit a job ARRAY — run the script N times, each task with its own `$SLURM_ARRAY_TASK_ID`(resources) set with `#SBATCH` directives at the top of the file, not as command-line flags |
||
cancel a queued or running job by its job ID. |
scancel JOBID cancel that one job-u "$USER" cancel ALL of your jobs at once (use with care) |
||
copy files to or from a remote machine over ssh — a simple one-shot transfer. |
file host:path copy a local file UP to the remotehost:path . copy a remote file DOWN to here-r copy a directory and everything in it |
||
show the cluster’s partitions (queues) — their names, time limits, and how busy they are. |
sinfo list the partitions with their `STATE` (`idle`, `mix`, `alloc`) and `TIMELIMIT` |
||
run a script in the CURRENT shell (not a child), so the variables, functions, and PATH changes it makes persist. |
source FILE / . FILE execute FILE’s lines in this shell — `.` is the POSIX spelling of the same thing |
||
show the job queue — what is pending, running, and whose. |
-u "$USER" only YOUR jobs (the everyday view)-j JOBID one specific job by idST column the state: `PD` pending (waiting in line), `R` running, `CG` completing |
||
open a shell on a remote machine — or run a single command there — over an encrypted connection. |
user@host log in as `user` on `host` and get an interactive remote shellhost CMD run ONE command on the remote and return (e.g. `ssh euler squeue`)-i keyfile authenticate with a specific private key-p N connect on port N (the default is 22) |
||
bundle many files and directories into one archive (and, with -z, compress it) — for transport or backup. |
-czf a.tar.gz dir/ CREATE a gzip-compressed archive of dir/ (c=create, z=gzip, f=file)-xzf a.tar.gz EXTRACT a gzip archive-tzf a.tar.gz LIST an archive’s contents without extracting-C dir change to dir first — archive from, or extract into, a chosen directory |
||
run a persistent terminal that survives disconnects — detach, log out, and reattach later with your work still running. |
tmux start a new sessionCtrl-b d DETACH — leave it running and drop back to your normal shelltmux attach / tmux a re-attach to the running session after you reconnecttmux ls list running sessions |
||
watch processes live — a continuously updating table of what is using the CPU and memory. |
top start the live view (press `q` to quit)htop a friendlier colour version, if installed — scrollable, with click-to-kill |
||
re-run a command every couple of seconds and show its latest output in place — to watch something change. |
watch CMD re-run CMD every 2 seconds (e.g. `watch squeue` to watch a job queue)-n N set the interval to N seconds-d highlight what changed since last time |
Part V
Command |
Job |
Workhorse flags |
Introduced in |
|---|---|---|---|
run a Makefile — build each target from its prerequisites, rebuilding only what is out of date. |
make build the first (default) target in `Makefile`make TARGET build a specific target by name (e.g. `make clean`, `make results.txt`)-n dry-run — PRINT the commands it would run, without running them (the `–dry-run` habit, Notebook 15)-j N run independent recipes in parallel across N jobs (the `xargs -P` idea, Notebooks 5 & 17) |