Skip to main content

Linux administration cheatsheet

A one-page reference for Linux administration. For the full filesystem hierarchy, package management, and shell-scripting deep-dive, see the complete guide.

๐Ÿ“– Full guide: Linux Administration โ†’ Beginner
Learn this in 5 minutes5 min
  1. Begin with the grep card
  2. Then the sed and Permissions cards
  3. Treat the other 5 cards as lookups โ€” scan by card title when you need one
  4. Open the full guide when a card isn't enough

grepโ€‹

grep -rn "TODO" src/
grep -riE "error|fail|panic" app.log
grep -v "^#" config.conf # invert โ€” strip comments
grep -c "ERROR" app.log
grep -A3 -B1 "Exception" app.log
grep -oP '(?<=user=)\w+' access.log

sedโ€‹

sed 's/foo/bar/g' file
sed -i.bak 's/foo/bar/g' file # in-place with backup
sed -n '10,20p' file
sed '/^$/d' file # delete blank lines
sed -n '/START/,/END/p' file

Permissionsโ€‹

chmod 755 script.sh
chmod u+x script.sh
chown user:group file

r=4 w=2 x=1 per owner/group/other. 755 = rwxr-xr-x.

Process managementโ€‹

ps aux --sort=-%cpu | head
kill -15 PID # graceful
kill -9 PID # force
systemctl status nginx
systemctl restart nginx
journalctl -u nginx -f

Disk & storageโ€‹

df -h
du -sh */ | sort -h
lsof +D /path

SSH & cronโ€‹

ssh -i key.pem user@host
scp file.txt user@host:/path/
crontab -e
# m h dom mon dow command
0 2 * * * /opt/backup.sh

Networking from the OS sideโ€‹

ss -tulpn
ip addr
curl -o /dev/null -s -w "%{time_total}\n" https://example.com

Environment variablesโ€‹

export PATH="$PATH:/opt/tool/bin"
echo $HOME
env | grep MY_VAR

.bashrc/.zshrc for interactive shells, /etc/environment for system-wide.

See: Interview-Ready Q&A