Bash Cheat Sheet
Searchable reference for everyday Bash commands.
| Command | Description |
|---|---|
| ls -la | List files including hidden, long format |
| ls -lhS | Sort by size, human-readable |
| cd <dir> | Change directory |
| cd - | Jump to previous directory |
| pwd | Print working directory |
| tree -L 2 | Show directory tree, depth 2 |
| stat <file> | Show file metadata (size, perms, mtime) |
| file <path> | Detect file type by content |
| mkdir -p a/b/c | Make nested directories |
| rm -rf <dir> | Remove directory recursively |
| cp -r <src> <dst> | Copy directory recursively |
| mv <src> <dst> | Move / rename |
| ln -s <target> <link> | Create symbolic link |
| touch <file> | Create empty file or bump mtime |
| cat <file> | Print file contents |
| less <file> | Page through a file |
| head -n 20 <file> | First 20 lines |
| tail -f <file> | Follow file output |
| tail -n +2 f | Skip first line (e.g. CSV header) |
| wc -l <file> | Count lines |
| sort -u <file> | Sort and de-duplicate |
| uniq -c | Group identical adjacent lines with counts |
| grep -r 'pat' . | Recursive grep |
| grep -nEi 'pat' f | Line numbers, ERE, case-insensitive |
| grep -v 'pat' f | Invert match (lines NOT matching) |
| rg 'pat' | ripgrep — fast recursive search |
| find . -name '*.cs' | Find files by name |
| find . -mtime -1 | Files modified in last 24h |
| find . -type f -size +10M | Files larger than 10 MB |
| sed 's/foo/bar/g' f | Stream edit (replace globally) |
| sed -i 's/foo/bar/g' f | Edit file in-place |
| awk '{print $1}' f | Print first column |
| awk -F, '{sum+=$2} END{print sum}' f | Sum a CSV column |
| xargs -n1 -P4 cmd | Run cmd in parallel, 4 at a time |
| tee -a <file> | Pipe + append to file (and stdout) |
| cut -d: -f1 /etc/passwd | Slice columns by delimiter |
| chmod 755 <file> | Set file permissions |
| chmod +x <file> | Make executable |
| chown user:group f | Change file owner |
| umask 022 | Default permission mask |
| ps aux | grep app | Find running process |
| pgrep -f app | PID of process by name pattern |
| kill -9 <pid> | Force-kill process |
| killall <name> | Kill all by name |
| top / htop | Live process viewer |
| nohup cmd > out.log 2>&1 & | Detach from terminal |
| jobs ; bg ; fg %1 | Background / foreground jobs |
| df -h | Disk space (human readable) |
| du -sh <dir> | Folder size |
| du -sh * | sort -h | Largest items in this directory |
| free -h | Memory in human units |
| uname -a | Kernel / arch / hostname |
| uptime | Load average and uptime |
| tar -czf a.tgz d/ | Create gzipped tar |
| tar -xzf a.tgz | Extract gzipped tar |
| tar -tzf a.tgz | List contents of tarball |
| zip -r a.zip d/ | Create zip archive |
| unzip a.zip | Extract zip archive |
| curl -fsSL url | Quietly fetch and pipe |
| curl -I url | HEAD request — headers only |
| curl -o file url | Download to file |
| wget url | Download a URL |
| ssh user@host | SSH into host |
| scp f user@host:/p | Copy over SSH |
| rsync -avz src/ host:dst/ | Sync directories (compressed) |
| nc -zv host 443 | TCP port check |
| dig +short example.com | DNS lookup, short form |
| ss -tulpn | List listening sockets |
| export VAR=value | Set environment variable |
| unset VAR | Remove environment variable |
| env | sort | List env vars, sorted |
| history | grep cmd | Search shell history |
| !! | Re-run last command |
| !$ | Last argument of previous command |
| man <cmd> | Show command manual |
| type -a <cmd> | Where does this command come from? |
About this tool
Common file, process, archive and shell commands with one-line descriptions.