DEV Community

Hosni Zaaraoui
Hosni Zaaraoui

Posted on

Linux sysadmin tips & shortcuts

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 (0)