If you're working with Linux in real-world environments—whether for DevOps, sysadmin, or cloud engineering—this guide provides 50 practical, scenario-based Linux command examples you’ll actually use on the job.
Each one includes a use case, command, and explanation. Bookmark this! 🔖
1. 🔥 Kill the Process Consuming the Most Memory
Scenario: Server lag due to memory-hungry process.
ps aux --sort=-%mem | head -n 5
kill -9 <PID>
Explanation: Lists top memory users and kills the worst offender.
2. 🎧 Check Listening Ports and Services
Scenario: App fails to start—port in use.
ss -tuln
3. 💽 Detect Excessive Disk Writers
Scenario: EBS filling up due to log/temp files.
sudo apt update && sudo apt install iotop -y
sudo iotop -o
4. 🕒 Find Recently Modified Files (Last 2 Hours)
find /var/www -type f -mmin -120
5. 🧑💻 List All Processes by a Specific User
ps -u username
6. 👥 Create a Temporary User With Expiry
sudo useradd -e 2025-06-01 tempuser
sudo passwd tempuser
sudo chage -d 0 tempuser
7. 🔎 Find the Process Listening on a Specific Port
sudo lsof -i :8080
8. 🧠 Monitor Real-Time CPU Usage
top -o %CPU
9. ⏰ List All Cron Jobs for a User
crontab -u ubuntu -l
10. 📦 Backup Only .conf Files With Folder Structure
rsync -av --prune-empty-dirs \
--include='*/' \
--include='*.conf' \
--include='**/*.conf' \
--exclude='*' \
/etc/nginx/ backup/nginx/
11. 📋 Check Logs From Previous Boot
journalctl -b -1
12. 📊 Check Uptime and Load Averages
uptime
13. 🧟 Find Zombie Processes
ps aux | awk '$8=="Z" { print $0 }'
14. 💾 Find Directories Using Most Disk Space
du -h --max-depth=1 / | sort -hr
15. 🔍 Display Top 10 Largest Files in Directory Tree
find /var -type f -exec du -h {} + | sort -rh | head -n 10
16. 📈 Check Inode Usage
df -i
17. 📝 Monitor Real-Time Logs (systemd services)
journalctl -u nginx.service -f
18. 🌲 Monitor Real-Time Process Tree
pstree -p
19. 👀 Check Who Is Logged In
w
20. 🗡 Kill All Processes Belonging to a User
pkill -u tempuser
21. ❗ Watch Logs for "error" Messages in Real-Time
tail -f /var/log/syslog | grep -i --line-buffered "error"
22. 🌐 Check DNS Resolution
dig api.example.com +short
23. 📉 Limit Bandwidth While Using wget
wget --limit-rate=1m https://your-download-url
24. ⏲ Reboot System in 60 Seconds With Warning
sudo shutdown -r +1 "Rebooting for maintenance. Save your work."
25. 🧠 Watch Memory & CPU Usage of a Process
watch -n 2 "ps -p <PID> -o %cpu,%mem,cmd"
26. ⌛ Schedule One-Time Task with at
echo "reboot" | at now + 15 minutes
27. 🔗 Run Command Only if Previous One Succeeded
git pull && ./build.sh
28. 🔁 Retry Until a Command Succeeds
until curl -s http://localhost:8080/health; do sleep 5; done
29. 📦 Create Compressed Tarball
tar -czvf backup.tar.gz /path/to/folder
30. 📂 Extract a Tar.gz Archive
tar -xzvf backup.tar.gz
31. 💿 Show Disk Usage by Mounted Partition
df -h
32. 💽 Show Mounted Disks and Filesystems
lsblk -f
33. 🧮 Show Memory Usage Summary
free -h
34. 📦 List All Installed Packages (Debian)
dpkg -l
35. 🔄 Update and Upgrade All Packages
sudo apt update && sudo apt upgrade -y
36. 📜 Check Last 100 Lines of Nginx Log
tail -n 100 /var/log/nginx/access.log
37. 🔍 Recursively Search Files for Keyword
grep -r "TODO" .
38. 🔐 Securely Copy File to Remote Server
scp file.txt user@host:/remote/path/
39. 🚨 Find .log Files > 100MB
find /var/log -name "*.log" -size +100M
40. 🌐 Show All Open Network Connections
netstat -tulnp
41. 🔧 Manage Services with systemctl
sudo systemctl start nginx # Start service
sudo systemctl enable nginx # Enable at boot
sudo systemctl status nginx # Check status
42. 📡 Monitor Network Usage (iftop)
sudo apt install iftop -y
sudo iftop
43. 🧪 Manage Environment Variables
printenv # View env vars
export MY_VAR=value # Set temporarily
44. 👤 User and File Ownership/Permissions
cut -d: -f1 /etc/passwd # List users
ls -l filename # Check file ownership
sudo chown user:group file # Change owner
chmod +x script.sh # Make script executable
✅ Final Thoughts
These are not just commands—they’re real-world solutions to real-world problems. Whether you're troubleshooting a server spike, preparing a production deployment, or cleaning up a messy filesystem, this cheat sheet can save your day.
💬 Have a favorite Linux trick? Share it in the comments!
Top comments (0)