df -h
Show disk space usage for all mounted filesystems in human-readable format. Quick first check when a server reports disk full errors.
df -h
# Show specific filesystem
df -h /var/log
# Show inodes (useful when df shows free space but writes fail)
df -i
du -sh /*
Show disk usage by directory. Start at root and drill down to find what's eating disk space.
du -sh /*
# Top 10 largest directories under /var
du -h /var | sort -rh | head -10
# Find files larger than 100MB
find / -type f -size +100M 2>/dev/null
ps aux
List all running processes with CPU and memory usage. Pipe through sort and head to see the top consumers immediately.
# Top CPU consumers
ps aux --sort=-%cpu | head -20
# Top memory consumers
ps aux --sort=-%mem | head -20
# Find a specific process
ps aux | grep nginx
top
Interactive real-time process viewer. Press M to sort by memory, P for CPU, k to kill a process by PID.
# Non-interactive snapshot (useful in scripts)
top -b -n 1 | head -30
# Show threads
top -H
# Monitor specific PID
top -p 1234
free -h
Report memory and swap usage. The available column is what actually matters — it accounts for reclaimable cache.
free -h
# Watch memory every 2 seconds
watch -n 2 free -h
# Show memory in MB
free -m
systemctl
Manage systemd services. The most common daily driver for controlling daemons on modern Linux distributions.
systemctl status nginx
systemctl restart nginx
systemctl reload nginx # Reload config without restart
systemctl enable --now nginx # Enable + start in one step
systemctl list-units --failed # Show failed units
journalctl
Query the systemd journal. More powerful than grepping /var/log directly — filter by service, time range, or priority level.
# Recent errors with context
journalctl -xe
# Follow logs for a service
journalctl -fu nginx
# Logs since last boot
journalctl -b
# Last hour, errors only
journalctl --since "1 hour ago" -p err
ss -tulpn
List all listening TCP and UDP ports with the process name. Replacement for netstat — faster and available by default on modern distros.
# All listening ports with process names
ss -tulpn
# Established connections only
ss -tnp state established
# Check if port 80 is in use
ss -tulpn | grep :80
# Connection count by state
ss -s
Connection Counts
Count TCP connections by state. Useful when investigating connection exhaustion or TIME_WAIT buildup under load.
# Count by state
ss -tn | awk 'NR>1 {print $1}' | sort | uniq -c | sort -rn
# Top remote IPs by connection count
ss -tn state established | awk 'NR>1 {print $5}' \
| cut -d: -f1 | sort | uniq -c | sort -rn | head -20
tail / grep
Follow log files in real time or search for patterns. Combine with grep for filtering; use -A/-B flags for context lines.
# Follow a log file in real time
tail -f /var/log/syslog
# Show last 100 lines
tail -n 100 /var/log/nginx/error.log
# Follow + filter
tail -f /var/log/syslog | grep --line-buffered "error"
# Context around matches
grep -B2 -A5 "OOM" /var/log/syslog
lsblk -f
List block devices with filesystem types, labels, and UUIDs. Good first step when diagnosing mount issues or new disk provisioning.
lsblk -f
# Show disk info including model names
lsblk -o NAME,SIZE,MODEL,MOUNTPOINT
# Show UUIDs (useful for /etc/fstab)
blkid
strace
Trace system calls made by a process. Invaluable for debugging permission errors, missing files, and hangs — without source code.
# Attach to running process
strace -p 1234
# Filter by syscall type
strace -p 1234 -e trace=open,read,write
# Summary of syscall counts
strace -c -p 1234
# Trace a new command
strace ls /etc
kill / pkill
Send signals to processes. Always try SIGTERM (15) first — it lets the process clean up. SIGKILL (9) is the last resort and can leave temp files or locks behind.
# Graceful shutdown first
kill PID
# Force kill if it ignores SIGTERM
kill -9 PID
# Kill by name
pkill nginx
# Kill all matching, with confirmation prompt
pkill -e nginx
# Kill everything owned by a user
pkill -u www-data
iostat
Extended disk I/O statistics per device. Watch await (average I/O wait time in ms) and %util (device saturation). Values above 20ms await or 90% util are worth investigating.
# Extended stats, 1-second intervals, 5 samples
iostat -xz 1 5
# Key columns:
# r/s, w/s — reads/writes per second
# rkB/s — read throughput
# await — avg I/O response time (ms)
# %util — % of time device was busy
tcpdump
Capture and inspect network packets. Invaluable for confirming whether traffic is actually reaching a server, debugging TLS handshake failures, or tracing unexpected connections.
# Capture port 80 traffic on eth0
tcpdump -i eth0 -nn port 80
# Capture to file for Wireshark analysis
tcpdump -i eth0 -w /tmp/capture.pcap
# Show only SYN packets (new connections)
tcpdump -i eth0 'tcp[tcpflags] & tcp-syn != 0'
# Filter by host and port
tcpdump -i any host 10.0.0.5 and port 443
crontab
View and edit scheduled cron jobs. When a job isn't running, check the cron logs and verify the PATH — cron runs with a minimal environment, so absolute paths are safer.
# List current user's crontab
crontab -l
# Edit crontab
crontab -e
# List another user's crontab
crontab -u www-data -l
# Check cron execution logs
grep CRON /var/log/syslog | tail -20
# System-wide cron jobs
ls /etc/cron.d/ /etc/cron.daily/ /etc/cron.hourly/
awk for log parsing
Extract and aggregate data from structured log files. Faster than writing scripts for common tasks like counting 5xx errors or finding the top client IPs.
# Count HTTP 5xx errors in nginx access log
awk '$9 >= 500' /var/log/nginx/access.log | wc -l
# Top 10 client IPs by request count
awk '{print $1}' /var/log/nginx/access.log \
| sort | uniq -c | sort -rn | head -10
# Average response time (field 11 in some formats)
awk '{sum+=$11; count++} END {print sum/count "ms avg"}' /var/log/nginx/access.log
mtr / traceroute
Trace the network path to a host and measure per-hop latency. mtr combines ping and traceroute into a live view — better for diagnosing intermittent packet loss at a specific hop.
# Interactive live view
mtr example.com
# Non-interactive report (good for sharing)
mtr --report --report-cycles 10 example.com
# Classic traceroute (UDP by default)
traceroute example.com
# TCP traceroute (bypasses some firewalls)
traceroute -T -p 443 example.com
rsync
Efficiently sync files locally or over SSH. Transfers only changed blocks, preserves permissions and timestamps, and can resume interrupted transfers.
# Sync to remote host
rsync -avz --progress /src/ user@host:/dest/
# Dry run first — always a good idea
rsync -avzn /src/ user@host:/dest/
# Delete files at destination not in source
rsync -avz --delete /src/ /dest/
# Exclude directories
rsync -avz --exclude='*.log' --exclude='tmp/' /src/ /dest/
nginx config test
Always test nginx configuration before reloading. A bad config with a plain reload will silently fail; nginx -t catches syntax errors first without dropping connections.
# Test then reload in one command
nginx -t && systemctl reload nginx
# Test a specific config file
nginx -t -c /etc/nginx/nginx.conf
# Apache equivalent
apachectl configtest && systemctl reload apache2
# Show compiled-in modules and paths
nginx -V 2>&1 | tr -- - '\n' | grep -E 'prefix|conf'
vmstat
System-wide snapshot of CPU, memory, swap, and I/O every N seconds. The si/so (swap-in/swap-out) columns are the fastest way to confirm active swapping.
# Wide output, 1-second intervals, 10 samples
vmstat -w 1 10
# Key columns:
# r — processes waiting for CPU
# b — processes blocked on I/O
# si — swap read from disk (KB/s)
# so — swap written to disk (KB/s)
# us/sy/wa — user, sys, iowait CPU %
lsof
List open files for a process — includes regular files, sockets, pipes, and devices. Useful for finding deleted-but-open files, checking which files a process is writing to, or who has a file locked.
# All open files for a PID
lsof -p PID
# What's using port 8080
lsof -i :8080
# Files opened by a user
lsof -u www-data
# Deleted files still held open (disk leak)
lsof | grep deleted
# Network connections for a process
lsof -p PID -i