cheat-sheets

Modern CLI Tools

Faster, friendlier replacements and add-ons for classic Unix commands. Package names are for Ubuntu 24.04 unless noted. Use Homebrew on macOS (and Linux), or cargo install for the Rust ones. See Linux Basics for classic commands.

TOOLREPLACESINSTALL (APT)
ripgrep (rg)grep -rsudo apt install ripgrep
fdfindsudo apt install fd-find (binary is fdfind)
fzfinteractive filtersudo apt install fzf
batcatsudo apt install bat (binary is batcat)
ezalssudo apt install eza
zoxidecdsudo apt install zoxide
btoptop / htopsudo apt install btop
ncdudusudo apt install ncdu
tldrman summariessudo apt install tldr
httpie (http)curl for APIssudo apt install httpie
lazygitgit TUIbrew install lazygit, or the release binary
deltagit diff pagerbrew install git-delta
dustdu (visual tree)cargo install du-dust, or brew install dust
hyperfinetime (benchmarking)sudo apt install hyperfine

Some of these may be missing from older releases. Fall back to cargo install or a release binary. Aliases for Debian-renamed binaries:

bash
alias fd=fdfind
alias bat=batcat

ripgrep #

COMMANDDESCRIPTION
rg "text"Search recursively, respecting .gitignore
rg -i "text"Ignore case
rg -F "a.b"Fixed string, no regex
rg -l "text"File names only
rg -c "text"Count per file
rg -t py "def "Only Python files (rg --type-list)
rg -g '*.md' "text"Glob filter (-g '!dist' excludes)
rg -C 3 "text"Context lines
rg --hidden "text"Include hidden files
rg -n -e "a" -e "b"Multiple patterns
rg "foo" -r "bar"Show replacements (does not edit files)
rg -w "word"Whole-word match
rg -v "text"Invert: lines that do not match
rg -o "[0-9.]+"Print only the matching part
rg -U "start.*\n.*end"Multiline match
rg --filesList files that would be searched (like fd with ignore rules)
rg --files -g '*.yml'List files matching a glob
rg -z "text" file.gzSearch inside compressed files
rg --stats "text"Match and file counts
rg --json "text"JSON output for scripts (jq)
rg -uuu "text"Search everything: no ignore rules, hidden and binary files
rg -A 2 -B 1 "text"Lines after and before

For classic tools see Grep, SED Cheat-Sheet and AWK. Put defaults in a file and point RIPGREP_CONFIG_PATH at it (one flag per line, for example --smart-case).

fd #

COMMANDDESCRIPTION
fd nameFind by regex in file names
fd -e mdBy extension
fd -t dDirectories only (-t f files)
fd -H -I nameInclude hidden and ignored files
fd -e log -x gzip {}Run a command on each match
fd -e tmp -X rmOne command with all matches
fd -g '*.conf' /etcGlob instead of regex, in a given directory
fd -d 2 nameLimit search depth
fd --changed-within 1dModified in the last day (--changed-before too)
fd -S +100MLarger than 100 MB (-S -1k for smaller)
fd -E node_modules -E .git nameExclude paths
fd -p 'src/.*test'Match against the full path
fd -0 -e jpg | xargs -0 ls -lNUL-separated output for safe piping

fzf #

COMMANDDESCRIPTION
fzfPick a file interactively
Ctrl+RFuzzy search shell history (after the shell integration is enabled)
Ctrl+TPaste a file path
Alt+Ccd into a directory
git branch | fzf | xargs git checkoutPick a branch (Git)
kubectl get pods -o name | fzfPick a resource (Kubectl)
fzf --preview 'bat --color=always {}'File preview
fzf -mMulti-select with Tab
fzf --height 40% --reverseCompact inline layout
fzf -e / fzf '^start'Exact match / anchor to start ('word for exact term, !word to exclude)
fzf --bind 'enter:become(vim {})'Replace fzf with an editor on Enter

Enable key bindings in bash or zsh: eval "$(fzf --bash)" or source <(fzf --zsh) (fzf 0.48 and later; older packages ship a key-bindings.bash file instead).

Useful environment variables for your shell profile:

bash
export FZF_DEFAULT_COMMAND='fd --type f --hidden --exclude .git'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_DEFAULT_OPTS='--height 40% --layout=reverse --border'
export FZF_CTRL_T_OPTS="--preview 'bat -n --color=always {}'"

fzf Combos #

COMMANDDESCRIPTION
git switch "$(git branch --all | sed 's/^[* ]*//' | fzf)"Pick and switch branch (Git)
git log --oneline | fzf --preview 'git show --color=always {1}'Browse commits with a diff preview
git diff --name-only | fzf -m | xargs git addStage chosen changed files
docker ps -a --format '{{.Names}}' | fzf | xargs docker logs -fFollow logs of a chosen container (Docker)
docker exec -it "$(docker ps --format '{{.Names}}' | fzf)" shShell into a chosen container
kubectl get pods -o name | fzf | xargs kubectl logs -fLogs of a chosen pod (Kubectl)
kubectl config get-contexts -o name | fzf | xargs kubectl config use-contextSwitch cluster context
kill -9 $(ps -ef | sed 1d | fzf -m | awk '{print $2}')Pick processes to kill
rg --line-number . | fzf --delimiter : --preview 'bat --color=always --highlight-line {2} {1}'Search file contents interactively
rg -l "text" | fzf --preview 'bat --color=always {}'Files containing text, with preview
fd -t d | fzfPick a directory
cd "$(fd -t d | fzf)"cd into a chosen directory
ssh "$(grep '^Host ' ~/.ssh/config | cut -d' ' -f2 | fzf)"Pick an SSH host (OpenSSH Cheat-Sheet)
systemctl list-units --type=service --no-legend | fzfBrowse services

bat, eza, zoxide #

COMMANDDESCRIPTION
bat fileShow with syntax highlighting and line numbers
bat -p filePlain output (no decorations), good for piping
eza -lah --gitLong list with git status
eza --tree --level=2Tree view
eval "$(zoxide init bash)"Enable z in your shell (zsh for zsh)
z projJump to the most frequent matching directory
ziPick a directory interactively
bat -r 10:20 fileShow only lines 10 to 20
bat -l yamlForce a language (useful when piping)
bat --list-themesAvailable themes (set with BAT_THEME or --theme)
bat -A fileShow non-printable characters
bat cache --buildRebuild the syntax cache after adding syntaxes
eza -l --sort=modifiedSort by modification time (--sort=size, --reverse)
eza -T -L 2 --git-ignoreTree that respects .gitignore
eza -la --icons --group-directories-firstIcons (needs a Nerd Font) and directories first
eza -DDirectories only
zoxide add <DIR>Add a directory to the database manually
zoxide query -lList the database with scores
zoxide remove <DIR>Drop a directory

Handy aliases:

bash
alias ls='eza --group-directories-first'
alias ll='eza -lah --git --group-directories-first'
alias cat='bat -pp'    # plain, no pager; use `command cat` for the real one
export MANPAGER="sh -c 'col -bx | bat -l man -p'"    # coloured man pages

eval "$(zoxide init bash --cmd cd)" replaces cd itself with the zoxide-aware version.

delta #

A syntax-highlighting pager for git diff, git log -p and git show (Git). Install with brew install git-delta, winget install dandavison.delta, or the .deb from its releases page. Add to ~/.gitconfig:

ini
[core]
    pager = delta
[interactive]
    diffFilter = delta --color-only
[delta]
    navigate = true     # n / N jump between files
    line-numbers = true
    side-by-side = false
[merge]
    conflictStyle = zdiff3
COMMANDDESCRIPTION
git diffNow rendered with delta
git -c delta.side-by-side=true diffSide-by-side for one command
delta file1 file2Diff two files without git
git log -pHighlighted history with patches
delta --show-configPrint the active configuration

ncdu and dust #

Both find what is using disk space. ncdu is interactive; dust prints a tree with bars.

COMMANDDESCRIPTION
ncdu /varScan a directory, browse with arrows, d deletes, q quits
ncdu -x /Stay on one filesystem (skip mounts)
ncdu -o scan.json /srv && ncdu -f scan.jsonScan once, browse later (also over SSH)
ncdu --exclude node_modules .Skip a pattern
sudo ncdu -x /Include directories you cannot read as your user
dustTree of the current directory
dust -d 2Limit depth
dust -n 20Show 20 entries
dust -rReverse order (biggest at the bottom)
dust -X .gitIgnore a directory
dust -e '\.log$'Only count names matching a regex
dust -bDo not show percent bars
du -sh * | sort -hClassic fallback (Linux Basics)

btop #

COMMANDDESCRIPTION
btopResource monitor for CPU, memory, disks, network and processes
btop --utf-forceForce UTF-8 symbols on a limited terminal
btop --low-color16-colour mode (for example over a plain SSH session)
EscOpen the menu and options
fFilter processes
t / kToggle tree view / kill the selected process

Config lives in ~/.config/btop/btop.conf. For per-container usage see Docker (docker stats).

hyperfine #

Command-line benchmarking: runs a command many times and reports mean, spread and min/max.

COMMANDDESCRIPTION
hyperfine 'sleep 0.3'Benchmark one command
hyperfine 'fd -e md' 'find . -name "*.md"'Compare commands
hyperfine -w 3 '<CMD>'Three warm-up runs first
hyperfine -r 50 '<CMD>'Exactly 50 runs
hyperfine -p 'sync' '<CMD>'Run a prepare command before each timing
hyperfine -L tool rg,grep '{tool} -r foo .'Parameter scan over a list
hyperfine --export-markdown bench.md '<CMD>'Export results (also --export-json)
hyperfine -i '<CMD>'Ignore non-zero exit codes
hyperfine -N 'ls'No shell wrapper, for very fast commands

Combos #

COMMANDDESCRIPTION
rg -l "TODO" | xargs batView every file containing a string
rg --files | fzf --preview 'bat --color=always {}'Fuzzy open with preview
fd -e log -x gzipCompress every log under the current directory
fd -e jpg -x convert {} {.}.pngConvert in bulk, {.} is the name without extension
fd -t f -S +100M -x ls -lhList files bigger than 100 MB
fd -H '^\.env$' -X rg -l "PASSWORD"Hunt for plaintext secrets in env files
rg "ERROR" /var/log -g '*.log' --no-filename -o | sort | uniq -c | sort -rnCount error lines by text
fd -e md | fzf -m | xargs -o vimPick Markdown files to edit
dust -d 1 /var/lib/dockerSee what Docker is using (Docker)

Others Worth Knowing #

Not Verified #

Package names and availability vary by distro release and were not checked on a live system.

Search all sheets

Tip: / or Ctrl/Cmd+K to open, Esc to close.