DEV Community

Latchu@DevOps
Latchu@DevOps

Posted on

๐Ÿš€ 50 Real-Time Linux Commands for DevOps & System Admins

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>
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

4. ๐Ÿ•’ Find Recently Modified Files (Last 2 Hours)

find /var/www -type f -mmin -120
Enter fullscreen mode Exit fullscreen mode

5. ๐Ÿง‘โ€๐Ÿ’ป List All Processes by a Specific User

ps -u username
Enter fullscreen mode Exit fullscreen mode

6. ๐Ÿ‘ฅ Create a Temporary User With Expiry

sudo useradd -e 2025-06-01 tempuser
sudo passwd tempuser
sudo chage -d 0 tempuser
Enter fullscreen mode Exit fullscreen mode

7. ๐Ÿ”Ž Find the Process Listening on a Specific Port

sudo lsof -i :8080
Enter fullscreen mode Exit fullscreen mode

8. ๐Ÿง  Monitor Real-Time CPU Usage

top -o %CPU
Enter fullscreen mode Exit fullscreen mode

9. โฐ List All Cron Jobs for a User

crontab -u ubuntu -l
Enter fullscreen mode Exit fullscreen mode

10. ๐Ÿ“ฆ Backup Only .conf Files With Folder Structure

rsync -av --prune-empty-dirs \
  --include='*/' \
  --include='*.conf' \
  --include='**/*.conf' \
  --exclude='*' \
  /etc/nginx/ backup/nginx/
Enter fullscreen mode Exit fullscreen mode

11. ๐Ÿ“‹ Check Logs From Previous Boot

journalctl -b -1
Enter fullscreen mode Exit fullscreen mode

12. ๐Ÿ“Š Check Uptime and Load Averages

uptime
Enter fullscreen mode Exit fullscreen mode

13. ๐ŸงŸ Find Zombie Processes

ps aux | awk '$8=="Z" { print $0 }'
Enter fullscreen mode Exit fullscreen mode

14. ๐Ÿ’พ Find Directories Using Most Disk Space

du -h --max-depth=1 / | sort -hr
Enter fullscreen mode Exit fullscreen mode

15. ๐Ÿ” Display Top 10 Largest Files in Directory Tree

find /var -type f -exec du -h {} + | sort -rh | head -n 10
Enter fullscreen mode Exit fullscreen mode

16. ๐Ÿ“ˆ Check Inode Usage

df -i
Enter fullscreen mode Exit fullscreen mode

17. ๐Ÿ“ Monitor Real-Time Logs (systemd services)

journalctl -u nginx.service -f
Enter fullscreen mode Exit fullscreen mode

18. ๐ŸŒฒ Monitor Real-Time Process Tree

pstree -p
Enter fullscreen mode Exit fullscreen mode

19. ๐Ÿ‘€ Check Who Is Logged In

w
Enter fullscreen mode Exit fullscreen mode

20. ๐Ÿ—ก Kill All Processes Belonging to a User

pkill -u tempuser
Enter fullscreen mode Exit fullscreen mode

21. โ— Watch Logs for "error" Messages in Real-Time

tail -f /var/log/syslog | grep -i --line-buffered "error"
Enter fullscreen mode Exit fullscreen mode

22. ๐ŸŒ Check DNS Resolution

dig api.example.com +short
Enter fullscreen mode Exit fullscreen mode

23. ๐Ÿ“‰ Limit Bandwidth While Using wget

wget --limit-rate=1m https://your-download-url
Enter fullscreen mode Exit fullscreen mode

24. โฒ Reboot System in 60 Seconds With Warning

sudo shutdown -r +1 "Rebooting for maintenance. Save your work."
Enter fullscreen mode Exit fullscreen mode

25. ๐Ÿง  Watch Memory & CPU Usage of a Process

watch -n 2 "ps -p <PID> -o %cpu,%mem,cmd"
Enter fullscreen mode Exit fullscreen mode

26. โŒ› Schedule One-Time Task with at

echo "reboot" | at now + 15 minutes
Enter fullscreen mode Exit fullscreen mode

27. ๐Ÿ”— Run Command Only if Previous One Succeeded

git pull && ./build.sh
Enter fullscreen mode Exit fullscreen mode

28. ๐Ÿ” Retry Until a Command Succeeds

until curl -s http://localhost:8080/health; do sleep 5; done
Enter fullscreen mode Exit fullscreen mode

29. ๐Ÿ“ฆ Create Compressed Tarball

tar -czvf backup.tar.gz /path/to/folder
Enter fullscreen mode Exit fullscreen mode

30. ๐Ÿ“‚ Extract a Tar.gz Archive

tar -xzvf backup.tar.gz
Enter fullscreen mode Exit fullscreen mode

31. ๐Ÿ’ฟ Show Disk Usage by Mounted Partition

df -h
Enter fullscreen mode Exit fullscreen mode

32. ๐Ÿ’ฝ Show Mounted Disks and Filesystems

lsblk -f
Enter fullscreen mode Exit fullscreen mode

33. ๐Ÿงฎ Show Memory Usage Summary

free -h
Enter fullscreen mode Exit fullscreen mode

34. ๐Ÿ“ฆ List All Installed Packages (Debian)

dpkg -l
Enter fullscreen mode Exit fullscreen mode

35. ๐Ÿ”„ Update and Upgrade All Packages

sudo apt update && sudo apt upgrade -y
Enter fullscreen mode Exit fullscreen mode

36. ๐Ÿ“œ Check Last 100 Lines of Nginx Log

tail -n 100 /var/log/nginx/access.log
Enter fullscreen mode Exit fullscreen mode

37. ๐Ÿ” Recursively Search Files for Keyword

grep -r "TODO" .
Enter fullscreen mode Exit fullscreen mode

38. ๐Ÿ” Securely Copy File to Remote Server

scp file.txt user@host:/remote/path/
Enter fullscreen mode Exit fullscreen mode

39. ๐Ÿšจ Find .log Files > 100MB

find /var/log -name "*.log" -size +100M
Enter fullscreen mode Exit fullscreen mode

40. ๐ŸŒ Show All Open Network Connections

netstat -tulnp
Enter fullscreen mode Exit fullscreen mode

41. ๐Ÿ”ง Manage Services with systemctl

sudo systemctl start nginx         # Start service  
sudo systemctl enable nginx        # Enable at boot  
sudo systemctl status nginx        # Check status
Enter fullscreen mode Exit fullscreen mode

42. ๐Ÿ“ก Monitor Network Usage (iftop)

sudo apt install iftop -y
sudo iftop
Enter fullscreen mode Exit fullscreen mode

43. ๐Ÿงช Manage Environment Variables

printenv                # View env vars  
export MY_VAR=value     # Set temporarily
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

โœ… 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)