📡 You're offline — showing cached content
New version available!
Quick Access
Linux Reference

Linux / Bash

Essential shell commands, scripting, permissions, and process management.

All Topics

Navigation & File System

ls -lahS
List all files (including hidden) in long format, human-readable sizes, sorted by size descending.
Example: ls -lahS /var/log
find / -name "*.log" -mtime -7
Recursively find files by name pattern modified within the last 7 days.
Example: find /var -name "*.log" -mtime -3 -size +1M
du -sh * | sort -rh
Show disk usage of each item in current dir, sorted largest-first in human-readable form.
Example: du -sh /var/* | sort -rh | head -10
ln -s target link
Create a symbolic (soft) link — the link points to the target file/directory.
Example: ln -s /opt/app/bin/app /usr/local/bin/app
rsync -avz src/ dest/
Efficiently sync files/dirs with archive mode, verbose output, and compression. Preserves permissions.
Example: rsync -avz --delete ./dist/ user@server:/var/www/
tree -L 2 --dirsfirst
Display directory structure as a tree, limited to 2 levels deep, directories shown first.
Example: tree -L 3 -I node_modules

Process & System Management

ps aux --sort=-%mem
Show all running processes sorted by memory usage descending.
Example: ps aux --sort=-%cpu | head -15
kill -9 PID / pkill name
Force-kill a process by PID / kill all matching processes by name.
Example: pkill -f "node server.js"
systemctl start/stop/status
Manage systemd services — start, stop, restart, enable at boot.
Example: systemctl enable --now nginx
journalctl -fu service
Follow (tail) live logs for a specific systemd service unit.
Example: journalctl -fu nginx --since "1 hour ago"
htop / top -bn1
Interactive CPU/memory monitor / one-shot batch output for scripting.
Example: top -bn1 | grep "Cpu(s)"
nohup cmd & disown
Run a command immune to hangup signals, send to background, and detach from shell.
Example: nohup ./server.sh > server.log 2>&1 & disown

Permissions & Users

chmod 755 / chmod u+x
Set file permissions numerically (rwxr-xr-x) or symbolically (add execute for owner).
Example: chmod -R 644 /var/www/html/
chown user:group file
Change ownership of a file or directory (recursively with -R).
Example: chown -R www-data:www-data /var/www/
sudo -u user cmd
Run a command as a different user (not just root).
Example: sudo -u postgres psql -c "SELECT 1"
passwd / adduser / usermod
Change password / add new user / modify user group membership.
Example: usermod -aG sudo deployuser
umask 022
Sets the default permission mask for newly created files (removes write for group/other).
Example: umask 027 # new files: 640, dirs: 750
setfacl / getfacl
Set/get fine-grained Access Control Lists beyond standard rwx.
Example: setfacl -m u:john:rx /shared/data/

Networking & SSH

ss -tulnp / netstat -tulnp
Show all TCP/UDP listening ports with the process that owns each socket.
Example: ss -tulnp | grep :80
curl -I / wget -q
Fetch HTTP headers only / silently download a file.
Example: curl -I -L https://api.example.com/health
ssh -L 8080:localhost:80 host
SSH local port forwarding — tunnel remote port 80 to your local 8080.
Example: ssh -L 5432:db-host:5432 bastion-server
scp / sftp
Securely copy files between hosts / interactive file transfer over SSH.
Example: scp -r user@host:/var/log/ ./logs/
iptables / ufw allow 22
Manage firewall rules / use UFW (Uncomplicated Firewall) for easy rule management.
Example: ufw allow from 10.0.0.0/8 to any port 22
dig / nslookup / whois
DNS lookup and query tools for troubleshooting name resolution.
Example: dig +short MX example.com

Shell Scripting

#!/usr/bin/env bash
Portable shebang — uses the system's env to locate bash, works across distros.
Example: #!/usr/bin/env bash\nset -euo pipefail
set -euo pipefail
Exit on error (-e), treat unset vars as errors (-u), catch pipeline failures (-o pipefail).
Example: set -euo pipefail; trap cleanup EXIT
${var:-default}
Parameter expansion — use default value if variable is unset or empty.
Example: PORT=${PORT:-3000}; ENV=${ENV:-production}
for f in *.log; do ... done
Glob-based for loop to iterate over matching files.
Example: for f in *.sql; do mysql db < "$f"; done
grep / sed / awk
Search patterns / stream editor / column-aware text processor — the Unix trinity.
Example: awk -F',' '{print $1, $3}' data.csv | sort -u
trap 'cleanup' EXIT ERR
Register a cleanup function to run when the script exits normally or on error.
Example: trap 'rm -f /tmp/lock.$$' EXIT ERR INT

Power Tools & I/O

tee / xargs / parallel
Tee splits output to file+stdout / xargs builds commands from stdin / parallel runs in parallel.
Example: cat urls.txt | parallel -j4 curl -s {}
jq '.[] | select(.status=="active")'
Powerful CLI JSON processor — filter, transform, and query JSON from the command line.
Example: curl api/users | jq '.data[].email'
cron / crontab -e
Schedule recurring commands. Format: min hr dom mon dow command.
Example: 0 2 * * * /usr/local/bin/backup.sh
env / export / printenv
Set/export environment variables for the current shell and child processes.
Example: export NODE_ENV=production PORT=8080
tar -czf archive.tar.gz dir/
Compress a directory into a gzipped tarball. Use -xzf to extract.
Example: tar -czf backup-$(date +%F).tar.gz /var/www/
watch -n2 'df -h'
Repeatedly execute a command every N seconds and display the output.
Example: watch -n1 'ss -tulnp | grep :80'