Code & computing / QUICK REFERENCE
Bash & Linux essentials
Navigate files, inspect text, handle quoting and control a shell without relying on destructive shortcuts.
Inspect files and space
- First twenty lines
head -n 20 notes.txtReads the beginning of a text file. [2]
- Last twenty lines
tail -n 20 notes.txtReads the end of a text file. [2]
- Follow a rotating log
tail -F app.logGNU behavior retries the filename after rotation. [2]
- Count lines
wc -l notes.txtCounts newline characters. [2]
- File metadata
stat notes.txtShows size, times and permissions. [2]
- Disk space by filesystem
df -hReports mounted filesystem usage. [2]
- Directory disk usage
du -sh logsSummarizes allocated space beneath logs. [2]
- Create nested directories
mkdir -p "project files/output"Creates absent parents without deleting contents. [2]
Find text and paths
- Literal text search
grep -nF -- "error" app.logPrints matching line numbers without regex interpretation. [3]
- Case-insensitive search
grep -ni -- "warning" app.logCase matching follows the active locale. [3]
- Recursive fixed-string search
grep -rnF -- "TODO" srcSearches files beneath src. [3]
- Exclude matching lines
grep -v -- "debug" app.logPrints nonmatching lines. [3]
- List matching filenames
grep -rlF -- "TODO" srcEmits matching filenames, not matching text. [3]
- Find files by suffix
find . -type f -name '*.py'Quotes keep the shell from expanding the pattern. [4]
- Find directories by name
find . -type d -name node_modulesLists matching directories without deleting them. [4]
- Find recent files
find . -type f -mtime -1Matches files modified within the previous 24 hours. [4]
Quoting and data flow
- Literal string
printf '%s\n' '$HOME'Single quotes keep the dollar sign literal. [1]
- Expand a variable safely
printf '%s\n' "$HOME"Double quotes preserve the value as one argument. [1]
- Set a shell variable
project='my project'No spaces around the assignment operator. [1]
- Export to child processes
export PROJECT_NAME='atlas'Makes the value available to subsequently launched children. [1]
- Capture output
today=$(date +%F)Captures stdout; trailing newlines are removed. [1]
- Pipe output to a command
printf '%s\n' one two | wc -lSends stdout through the pipe. [1]
- Redirect with overwrite
printf '%s\n' draft > notes.txtCreates or replaces notes.txt: existing contents are lost. [1]
- Append to a file
printf '%s\n' next >> notes.txtAdds to the end instead of truncating. [1]
Interactive shell controls
- Move to line start
- Ctrl+a
Default Emacs-style readline binding. [1]
- Move to line end
- Ctrl+e
Default Emacs-style readline binding. [1]
- Search previous commands
- Ctrl+r
Review the matched command before executing it. [1]
- Cancel foreground command
- Ctrl+c
Sends an interrupt; applications may handle it differently. [1]
- Suspend foreground job
- Ctrl+z
Stops, rather than terminates, a job. [1]
- List this shell's jobs
jobsDoes not list every system process. [1]
- Resume in foreground
fgResumes the current job on your terminal. [1]
- Show previous exit status
printf '%s\n' "$?"Run immediately after the command of interest. [1]
Reserved placement, separate from reference controls. No ad network is active.
No matching entry. Try a shorter word or clear the search to see the complete sheet.
Sources
cheatsheetatlas.com/sheets/bash/ · Updated 2026-10-19 · Bash 5.x / GNU userland