Process & Port Management
Find what’s using a port:
ss -tulnp | grep :8080
Kill process by port:
kill -9 $(lsof -t -i:8080)
Top processes (better than top):
btop
Show process tree:
ps auxf
File & Disk Tricks
Human-readable disk usage:
df -h
du -sh *
Find large files:
find / -type f -size +500M 2>/dev/null
Quickly clean logs:
truncate -s 0 /var/log/syslog
Search Like a Pro
Grep with line numbers + ignore case:
grep -in "error" file.log
Recursive search:
grep -r "password" /etc
Use less smarter:
/pattern → search
Shift+G → go to end
Networking Essentials
Check open ports:
ss -tuln
Test connectivity:
nc -zv 192.168.1.10 80
Show IPs:
ip a
Live traffic sniff:
tcpdump -i eth0
Services & Systemd
Check service status:
systemctl status nginx
Restart service:
systemctl restart nginx
View logs:
journalctl -u nginx -f
Memory & Performance
Memory usage:
free -h
CPU + memory snapshot:
top
IO stats:
iostat
Terminal Shortcuts (Huge Time Savers)
Ctrl + C → kill command
Ctrl + Z → pause (background it)
fg → bring back
Ctrl + A → start of line
Ctrl + E → end of line
Ctrl + R → search history 🔥
History & Productivity
Show history:
history
Re-run last command:
!!
Re-run command with sudo:
sudo !!
Permissions & Ownership
Change ownership:
chown user:user file
Change permissions:
chmod 755 script.sh
Package Management (Debian/Ubuntu)
Update & upgrade:
apt update && apt upgrade -y
Find package:
apt search nginx
Remove package:
apt remove nginx
Debugging & Logs
Follow logs live:
tail -f /var/log/syslog
Last 100 lines:
tail -n 100 file.log
Watch command output:
watch -n 2 "df -h"
Pro-Level Tricks
Run command in background:
nohup command &
Run multiple commands safely:
command1 && command2
Pipe like a wizard:
cat file | grep error | sort | uniq
Temporary Python web server:
python3 -m http.server 8000
Bonus (Sysadmin Mindset)
Always check logs first (/var/log or journalctl)
If something uses a port → ss + lsof → kill
If service fails → systemctl status + journalctl
If server slow → top + iostat + free
Top comments (2)
Your example is what's called
catabuse, sincegrepcan handle what you're after:grep error file | sort | uniq. I have to remind myself not infrequently that I don't need to pipecattogrep.Typically I would not truncate a file to
0, mainly because as you mention, "Always check logs first". In that case, something like this to preserve 500M of the file while removing the rest. Try this:truncate -s 500M messagesI really liked this command
kill -9 $(lsof -t -i:8080)not something I would've thought of to remove the process occupying a specific port, this could come in handy for containers when using something like docker compose.You’re absolutely right on the “cat abuse” — grep error file is cleaner and faster. Easy habit to fall into.
And yeah, that lsof + kill combo is a lifesaver, especially when Docker leaves ports hanging.
Appreciate the insights!