Text and streams
-
cat — print a whole file
The cat command prints a file's contents to the terminal and joins several files into one stream.
5 mincatcat -ncat -A -
less — page through a long file with search
The less pager shows a long file or command output screen by screen — scroll, search by word, follow the end.
5 minlessless -Nless -S -
head — the first lines of a file
The head command prints the beginning of a file or of command output — 10 lines by default, -n sets how many.
4 minheadhead -nhead -c -
tail — the last lines and following a log
The tail command prints the end of a file, and with -f it keeps showing new lines as they are appended to a log.
5 mintailtail -ntail -f -
Basic file commands
Navigation and files — ls, cd, cp, mv, rm, cat, less, head, tail, terminal copy-paste.
8 minls -lahcd dirpwd -
Bash scripts: running, variables, arguments
A script is a text file of shell commands: the #! line picks the interpreter, arguments arrive in $1, $2 and "$@".
9 minset -euochmodbash -
tee — output to a file and the screen
Splits a stream: writes to a file AND shows it on screen; sudo tee to write into protected files.
3 mincmdecho x -
echo — printing text
Printing strings and variables; -n and -e, escaping, when to prefer printf.
3 minechoecho -nprintf -
grep — searching text
The grep command finds lines matching a pattern in files and command output: regex, recursion, context.
4 mingrep -igrep -rngrep -v -
wc — count lines, words and bytes
The wc command counts lines (-l), words (-w), bytes (-c) and characters (-m) in a file or in command output.
4 minwcwc -lgrep error -
sort — sort lines
The sort command orders lines of a file or command output: as text, as numbers (-n), by field (-k), reversed (-r).
6 minsortsort -nsort -rn -
uniq — remove or count repeated lines
The uniq command collapses adjacent identical lines and counts them with -c; sort almost always comes before it.
5 minsort file -
cut — cut fields out of lines
The cut command takes fields out of every line by a delimiter (-d and -f) or characters by position (-c).
5 mincutcut -c1-8cut -f2 -
Glob patterns and brace expansion
Shell substitutions — * ? [] {} — and how they differ from regular expressions.
4 minmkdir -pcpecho -
Output redirection and pipelines
The shell sends a command's input and output to a file or another command — >, >>, 2>&1, /dev/null, the | pipe.
6 mincmdcmd1 -
sed and awk — editing and fields in a text stream
sed edits and deletes lines by pattern, awk splits lines into fields and computes over them, line by line.
10 minsed -nsedawk -
Regular expressions — patterns for grep, sed and awk
A regular expression is a pattern that many strings match; grep searches by it, sed replaces by it, awk selects lines.
6 mingrep -igrep -Egrep -
xargs — building arguments from a stream
Turns stdin lines into a command's arguments; without -0, file names with spaces and newlines break the parsing.
3 minfind -
sort, uniq, cut, wc, tr — text stream processing
Small pipeline utilities; uniq only removes adjacent duplicates, so it almost always needs sort before it.
5 minsort -usort filecut -
diff and patch — comparing and applying changes
Comparing files and applying patches: diff two configs, see what changed, apply a patch.
4 mindiff -udiff -qrdiff -
jq — processing JSON on the command line
Parsing and filtering JSON on the command line — fields, arrays, filters, formatting.
4 minjqjq -rjq --arg -
Environment variables and PATH
Environment variables: env, export, $PATH, ~/.bashrc and profiles; where "command not found" comes from.
4 minechoenvprintenv -
printf and echo — printing text in scripts
Formatted output in the shell — more reliable than echo, formats and special characters.
4 minprintfprintf -v -
vim — editing files in the terminal
The bare minimum for editing configs; Esc always returns to Normal mode, where letters are commands, not text.
4 mini -
nano — a simple console editor
A friendly console editor — save, quit, search, for editing config files.
3 minnano filenanonano -w -
date — date and time in the shell
The date command: current time, output formats, timestamps for files and logs, date arithmetic.
4 mindatedate -ddate -Iseconds -
Locale and encoding
Language, encoding and formats — LANG/LC_*, generating locales, UTF-8 problems.
4 minlocalelocale -alocale-gen