Bash / Shell Cheatsheet
Everyday bash for the command line. Works in zsh with minor differences.
1 credit
Navigation & files
7 itemsCurrent dir
pwdList (long, hidden, human)
ls -lahChange dir / home
cd <path> / cd ~Previous dir
cd -Create / remove dir
mkdir -p a/b/c / rmdir <d>Copy / move / remove
cp -r src dst / mv / rm -rfFind files
find . -name "*.ts" -type fText processing
6 itemsView / paginate
cat file / less file / head -n 20Search lines
grep -rni "term" .Replace in place
sed -i.bak 's/old/new/g' fileColumn extract
awk '{print $1,$3}' fileSort / unique / count
sort | uniq -c | sort -rnWord/line count
wc -l filePipes & redirection
6 itemsPipe stdout
cmd1 | cmd2Overwrite file
cmd > fileAppend
cmd >> fileRedirect stderr
cmd 2> errors.logMerge stderr + stdout
cmd > out.log 2>&1Discard
cmd > /dev/null 2>&1Processes & jobs
5 itemsRunning processes
ps aux / top / htopKill by PID / name
kill -9 <pid> / pkill <name>Listening ports
lsof -iTCP -sTCP:LISTEN -n -PRun in background
cmd &Disown (survive exit)
nohup cmd & / disownScripting
bash
#!/usr/bin/env bash
set -euo pipefail
NAME="${1:-world}"
for i in {1..3}; do
echo "$i hello, $NAME"
done
if [[ -f .env ]]; then
source .env
fiAlways start scripts with `set -euo pipefail` — errors halt, undef vars error, pipe failures propagate.