All Cheat Sheets

Linux / Shell Cheat Sheet

Essential Linux and Bash/Zsh commands — file operations, permissions, processes, networking, and text processing.

File Operations

List filesls -la
Change dircd /path/to/dir
Copycp -r src/ dest/
Move / renamemv old new
Removerm -rf dir/
Create dirmkdir -p path/to/dir
Find filesfind . -name '*.ts' -type f
File sizedu -sh dir/
Disk usagedf -h

Text Processing

Search textgrep -rn 'pattern' .
Replace textsed -i 's/old/new/g' file
Column extractawk '{print $1}' file
Sort linessort file.txt
Unique linessort file.txt | uniq
Count lineswc -l file
Headhead -n 20 file
Tail (follow)tail -f logfile

Permissions

Change permschmod 755 file
Change ownerchown user:group file
Make executablechmod +x script.sh
Numeric modeschmod 644 file # rw-r--r-- chmod 600 key # rw------- chmod 755 dir # rwxr-xr-xr=4, w=2, x=1 — digits are owner, group, others
Symbolic modeschmod u+x,g-w,o-r file chmod a+r file chmod go= fileu=user, g=group, o=others, a=all; + add, - remove, = set exactly
Recursivechmod -R 755 dir/ chown -R www-data:www-data /var/www
Dirs vs filesfind . -type d -exec chmod 755 {} + find . -type f -exec chmod 644 {} +
Change groupchgrp developers file
Default maskumask # show, e.g. 0022 umask 027 # new files 640, dirs 750
Setuid / setgid / stickychmod u+s bin # 4xxx chmod g+s dir # 2xxx chmod +t /tmp # 1xxx
View permissionsls -l file stat -c '%a %U:%G %n' filestat -c is GNU; on macOS use stat -f '%Lp %Su:%Sg %N'

Process Management

List processesps aux | grep node
Kill processkill -9 <pid>
Backgroundcommand &
Top / htophtop
Port usagelsof -i :3000

Networking

Downloadcurl -O https://example.com/file
HTTP requestcurl -X POST -d '{"a":1}' url
DNS lookupdig example.com
Pingping -c 4 example.com
Open portsss -tuln
SSHssh user@host
SCP copyscp file user@host:/path

Archives

Create tar.gztar -czf archive.tar.gz dir/
Extract tar.gztar -xzf archive.tar.gz
Zipzip -r archive.zip dir/
Unzipunzip archive.zip

Bash Scripting

Shebang & strict mode#!/usr/bin/env bash set -euo pipefail-e exit on error, -u error on unset vars, -o pipefail fail if any pipe stage fails
Variablesname="world" # no spaces around = echo "Hello, $name" echo "${name}s"
Command substitutiontoday=$(date +%F)
Arguments$0 script name $1 first arg $# arg count "$@" all args (quoted) $? last exit code
Default valueport="${PORT:-3000}"
If / elseif [[ -f "$file" ]]; then echo "exists" elif [[ -z "$var" ]]; then echo "empty var" else echo "nope" fi
Test operators-f file -d dir -e exists -z empty -n non-empty == != (strings) -eq -ne -lt -gt (numbers)
For loopfor f in *.log; do echo "$f" done for i in {1..5}; do echo "$i"; done
While read loopwhile IFS= read -r line; do echo "$line" done < file.txt
Casecase "$1" in start) start_app ;; stop) stop_app ;; *) echo "usage: $0 start|stop"; exit 1 ;; esac
Functionsgreet() { local name="$1" echo "Hi, $name" } greet "Ada"
Exit codescommand || echo "failed" command && echo "ok" exit 10 = success, non-zero = failure
Arithmeticcount=$((count + 1))
Arraysarr=(a b c) echo "${arr[0]}" "${#arr[@]}" for x in "${arr[@]}"; do echo "$x"; done
Cleanup on exittrap 'rm -f "$tmp"' EXIT
Redirectioncmd > out.log 2>&1 # stdout + stderr to file cmd 2>/dev/null # discard errors cmd | tee out.log

systemd & journalctl

Service statussystemctl status nginx
Start / stop / restartsudo systemctl start nginx sudo systemctl stop nginx sudo systemctl restart nginx
Reload configsudo systemctl reload nginx
Enable at bootsudo systemctl enable --now nginx--now also starts it immediately
Disable at bootsudo systemctl disable nginx
List failed unitssystemctl --failed
Reload unit filessudo systemctl daemon-reloadRun after editing a .service file
Service logsjournalctl -u nginx
Follow logsjournalctl -u nginx -f
Logs since timejournalctl -u nginx --since "1 hour ago"
Errors this bootjournalctl -b -p err

Free tools for this

Keep the references coming

One email a week: new and trending developer tools, fresh comparisons, and what shipped. Unsubscribe in one click.