Nifty CLI Commands

A handful of shell tricks worth keeping in your back pocket.

diff <(sort a.txt) <(sort b.txt)

Process substitution. Feeds command output to another command as if it were a file, no temp files needed.

fd . -e py | entr -c pytest

Reruns a command every time a watched file changes. Great for a tight test loop without a file-watcher plugin.

rg -n "TODO" --type py

Ripgrep: fast recursive search that respects .gitignore by default and prints line numbers with -n.

curl -s api.example.com | jq '.items[].name'

jq slices and filters JSON straight from a pipe, so no need to open a script just to peek at a response.

du -sh */ | sort -h

Sizes every directory one level down and sorts smallest to largest, a quick way to find what is eating disk space.

!!:gs/foo/bar

Reruns the last command with every "foo" swapped for "bar". Bash history expansion, no retyping required.

find . -name "*.log" -mtime +7 -delete

find doubles as a cleanup tool: locate files older than 7 days and remove them in one pass.

python3 -m http.server 8000

Instant static file server for the current directory, no setup, handy for quickly sharing a file on the LAN.