iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

Cheatsheet

The bash and Unix one-liners you reach for daily, on one page.

Daily bash

EXAMPLE
# Files + dirs
ls -lah; find . -maxdepth 2 -type d
tree -L 2
du -sh */ | sort -h        # size by dir
df -h                       # disk free

# Permissions + ownership
chmod 644 file; chmod 755 dir
chown -R user:group path

# Text
grep -rn 'TODO' src/
grep -E 'foo|bar' file
rg 'pattern'                # ripgrep, faster
sed -i.bak 's/old/new/g' file
awk -F, '{ print $1, $3 }' file.csv

# JSON
jq '.users[] | select(.tier == "pro") | .email' users.json
jq -r '.[].id' < items.json | xargs -I {} curl https://api/{}

# Processes
ps -ef | grep node
pgrep -fl node
htop                        # interactive
lsof -iTCP:3000 -sTCP:LISTEN
kill -TERM <pid>; kill -9 <pid>

# Networking
ss -tlnp                    # listening sockets
curl -fsS https://example.com -o body.html -D headers.txt
curl -X POST -H 'content-type: application/json' -d '{"a":1}' http://localhost:3000/
dig +short example.com
traceroute example.com

# Compression
tar -czf out.tar.gz dir/
tar -xzf out.tar.gz
zip -r out.zip dir/ ; unzip out.zip

# Archives + sync
rsync -aHAXP src/ user@host:/dst/
scp file user@host:/path/

# History
history | grep ssh
!! ; !$ ; !*

# Productivity
alias ll='ls -lah'
alias gs='git status'
alias gco='git checkout'
alias k='kubectl'

# Quick math
echo $((1 + 2 * 3))
python3 -c 'print(2**32)'

# Find slow queries
last | head -20
journalctl -u myapp -n 100 --no-pager
journalctl -u myapp -f       # follow

# One-liners
# Top 10 IPs by hits in nginx log
awk '{ print $1 }' access.log | sort | uniq -c | sort -rn | head

# Disk hogs
du -ah / 2>/dev/null | sort -rh | head -20

# Find files modified in last 24h
find . -type f -mtime -1

# Convert timestamps
date -u +%FT%TZ
date -d '@1718000000' +'%F %T'

Why it matters

Drill these patterns. Most of bash productivity is muscle memory: grep / sed / awk / xargs / jq for text; ss / lsof / dig for sockets; rsync for moving bytes. Once these are reflex, scripting fast becomes possible.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
ls cd pwd mkdir rm cp mv cat less grep find sed awk ps top kill jobs curl ssh chmod chown sort uniq
Try it Yourself »

Discussion

Loading…