Skip to content

💡 Practical Experience

The Survival Rule for Remote Operations

Before modifying SSH configurations, iptables rules, or fstab mounts, always open two terminals first. Use one to make changes, keep the other as a backup. If something goes wrong, use the other terminal to roll back.

Before editing /etc/fstab, always run mount -a first. If it errors out, your configuration is wrong — after reboot, the system will enter emergency mode. Use UUID instead of device names in fstab (device names may change, UUIDs won't).

Don't Panic When the Disk is Full

df -h shows the disk is full, but du -sh /* adds up to far less than the total capacity — this means there are deleted but unreleased files still held by processes.

bash
# Find occupied deleted files
lsof +L1 | grep deleted
nginx  1234  root  5w  REG  253,1  53687091200  0 /var/log/nginx/access.log (deleted)

# Free the space (without restarting the process)
truncate -s 0 /proc/1234/fd/5

# Or restart the occupying process
systemctl restart nginx

Don't Use kill -9

kill -9 (SIGKILL) is a nuclear bomb — the process is killed on the spot without cleanup. In most cases, kill (SIGTERM) is sufficient, giving the process 10 seconds to exit gracefully. Only use -9 when you've confirmed the process is stuck.

Use htop instead of top for process inspection — it supports mouse interaction, colors, and tree view, with 10x better experience.

The Three Essential Log Analysis Commands

For any log analysis need, these three commands cover 90% of cases:

bash
# 1. View recent logs
tail -f /var/log/syslog

# 2. Search for keywords
grep -i "error\|fail\|refused" /var/log/syslog | tail -50

# 3. Count frequency of occurrences
grep "error" /var/log/syslog | awk '{print $5}' | sort | uniq -c | sort -rn | head

tmpfs is a Great Tool

Place frequently read/written temporary files on tmpfs (memory filesystem) for a hundred-fold speed increase, and it won't wear out your SSD. Ideal for log buffers, session files, and compilation intermediate files.

bash
# Mount tmpfs
mount -t tmpfs -o size=512m tmpfs /tmp/app-cache

# Make it persistent in /etc/fstab
tmpfs /tmp/app-cache tmpfs size=512m,noexec,nosuid 0 0