⚑ Quick Reference

Keep the momentum going β€” everything you need on LearnXOps in one place:


Hey β€” It's Sandip Das πŸ‘‹

DevOps engineers must quickly diagnose and resolve system and network issues to ensure high availability and performance. These commands help in real-time debugging and performance monitoring.

System Debugging:

πŸ”Ή 10 Essential Linux Commands for System Monitoring & Troubleshooting


βœ… 1. top

Purpose: Real-time view of running processes and resource usage.
Use Case: Diagnosing unexpected system slowdowns.

top

Sample Output:

PID USER     PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
1234 root     20   0  400000  40000  10000 R  95.0   5.0   2:35.12 my_process
2345 ubuntu   20   0  200000  15000   5000 S   2.0   1.0   0:10.21 other_app

βœ… 2. htop

Purpose: Enhanced interactive version of top.
Use Case: Monitoring system during high-traffic events.

htop

Sample Output: A colorful, scrollable interface showing CPU, memory bars, and processes.


βœ… 3. df -h

Purpose: Check disk space usage.
Use Case: Detecting low disk space causing app failures.

df -h

Sample Output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       100G   95G   5G   95% /
tmpfs             8G   50M    8G    1% /dev/shm
/dev/sdb1       500G  450G  50G   90% /data

βœ… 4. du -h --max-depth=1 /path | sort -hr

Purpose: Check size of subdirectories.
Use Case: Finding large directories for cleanup.

du -h --max-depth=1 /path | sort -hr

Pro Tip (macOS/BSD):

du -h -d 1 /path | sort -hr

Sample Output:

50G /var/lib/docker
20G /var/log
10G /var/cache
5G  /var/www

βœ… 5. systemctl list-units --type=service --state=running

Purpose: Show running services.
Use Case: Identifying and optimizing running services.

systemctl list-units --type=service --state=running

Sample Output:

UNIT             LOAD   ACTIVE SUB     DESCRIPTION
apache2.service  loaded active running The Apache HTTP Server
mysql.service    loaded active running MySQL Community Server
sshd.service     loaded active running OpenSSH server daemon

βœ… 6. ps aux | grep [service_name]

Purpose: View specific service processes.
Use Case: Verifying services during troubleshooting.

ps aux | grep mysql

Sample Output:

mysql    5678  1.5  2.3 1660628 132624 ?  Ssl  11:45   5:24 /usr/sbin/mysqld

βœ… 7. ss -tulpn

Purpose: Show open ports and processes.
Use Case: Port inspection after firewall or security changes.

ss -tulpn

Sample Output:

Netid State  Recv-Q Send-Q Local Address:Port Peer Address:Port Process
 tcp   LISTEN 0      128    0.0.0.0:80      0.0.0.0:*        users:(("nginx",pid=1234,fd=6))
 tcp   LISTEN 0      50     127.0.0.1:3306  0.0.0.0:*        users:(("mysqld",pid=5678,fd=7))

βœ… 8. sar -q

Purpose: Historical CPU & load average data.
Use Case: Analyzing performance trends.

sar -q

Sample Output:

12:00:01 AM   runq-sz  plist-sz   ldavg-1   ldavg-5   ldavg-15
12:10:01 AM        1        180     0.11      0.15      0.13
12:20:01 AM        2        190     1.50      1.60      1.45
12:30:01 AM        3        200     3.80      2.90      2.50

βœ… 9. free -h

Purpose: Show memory and swap usage.
Use Case: Detecting memory leaks or exhaustion.

free -h

Sample Output:

              total   used   free   shared  buff/cache   available
Mem:           16G    12G    1G     500M    3G           2G
Swap:           8G     2G    6G

βœ… 10. fastfetch (or neofetch)

Purpose: Summary of OS, uptime, hardware, etc.
Use Case: Quickly assess an unknown server.

fastfetch    # or: neofetch

Sample Output:

OS: Ubuntu 22.04 LTS x86_64
Kernel: 5.15.0-56-generic
Uptime: 10 days, 4 hours
Memory: 16GB RAM
Shell: bash 5.1.8
CPU: Intel i7-9700K @ 4.90GHz
GPU: NVIDIA RTX 3080

ℹ️ Note: neofetch was archived in 2024 and is no longer maintained; fastfetch is the actively maintained drop-in replacement.


βœ… 11. Find CPU-Intensive Processes

ps -eo pcpu,pid,user,args --sort=-pcpu | head -10

Use Case: Troubleshoot slowdowns by identifying CPU-heavy processes.
Sample Output:

%CPU  PID   USER   COMMAND
90.2 12345 user1  /usr/bin/python3 script.py
75.6 67890 root   /usr/lib/jvm/java -jar app.jar
50.3 11223 user2  /opt/server/bin/server
35.7 44556 user3  /bin/bash ./heavy_script.sh

βœ… 12. Find Memory Leaks

watch -n 5 "ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head"

Use Case: Spot processes steadily growing in memory use.
Sample Output:

Every 5.0s: ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head
PID  PPID  CMD                          %MEM %CPU
5678 1234  /usr/bin/java -Xmx4G app.jar 75.5  8.2
6789 5678  /usr/bin/python3 server.py   50.3  6.4
7890 6789  node server.js               25.1  4.7

βœ… 13. Identify Disk I/O Bottlenecks

iostat -xz 1

Use Case: Check high disk read/write causing performance issues.
Sample Output:

Linux 5.15.0-56-generic (server01) 03/08/2025 _x86_64_ (8 CPU)

avg-cpu:  %user %nice %system %iowait %steal %idle
          10.3   0.0   5.1     80.2    0.0    4.4

Device:  rrqm/s wrqm/s r/s  w/s  rMB/s wMB/s avgrq-sz avgqu-sz await %util
sda      0.12   5.32   45.2 60.3 10.5  15.8   512.0    1.23     23.5   90.1

βœ… 14. Profile Application Performance

perf record -g -p [pid]

Then run:

perf report

Use Case: Pinpoint CPU-intensive functions in apps.
Sample Output:

# Overhead  Samples  Command  Shared Object         Symbol
35.2%       2034     java     libjvm.so             [.] C2Compiler::compile
20.3%       1502     python3  libc.so.6             [.] malloc
10.1%       872      node     v8.so                 [.] v8::internal::Heap::AllocateRaw

βœ… 15. Find File Access Patterns

sudo iotop -o

Use Case: Monitor active disk I/O by processes.
Sample Output:

Total DISK READ: 50.12 MB/s | Total DISK WRITE: 80.34 MB/s
PID  USER   DISK READ  DISK WRITE  COMMAND
1234 root   30.12 MB/s 40.34 MB/s  rsync -av /data /backup
5678 user1  10.00 MB/s 20.00 MB/s  python3 log_processor.py
7890 user2  5.00 MB/s  15.00 MB/s  mysqld --datadir=/var/lib/mysql

βœ… 16. Analyze System Load Averages

# LC_ALL=C prints 24-hour times, so column 4 is ldavg-1 (1-minute load)
LC_ALL=C sar -q | awk '$4 > 1.0'

Use Case: Find high load spikes in system history.
Sample Output:

00:00:01      runq-sz  plist-sz   ldavg-1   ldavg-5  ldavg-15
00:15:01            2       180      1.35      1.25      1.10
00:30:01            3       190      2.50      2.20      1.85
00:45:01            4       200      3.80      3.00      2.50

βœ… 17. Continuous Resource Monitoring

# dstat is no longer maintained; dool is its maintained fork (same flags)
sudo apt update && sudo apt install dstat -y   # or install dool
dstat -cdnmgy --top-cpu --top-mem

Use Case: Live monitoring during load testing.
Sample Output:

----total-cpu-usage---- ---disk/total--- ---net/total--- ---paging-- ---memory-usage---
usr sys idl wai hiq siq| read writ| recv send| in out | used free buff cach
  5   2   90  2   0   1 |  0    2  |  20   30 | 0   0  |  4G   2G   1G   3G
 10   3   85  1   0   1 |  5    8  |  50   60 | 0   0  |  5G   1G   1G   2G

βœ… 18. System Log File Monitoring

tail -f /var/log/syslog | grep ERROR

# On journald-only systems (RHEL, Fedora, newer Debian) there is no /var/log/syslog:
journalctl -f -p err

Use Case: Real-time log error tracking post-deploy.
Sample Output:

Mar 8 10:00:01 server app[1234]: ERROR Database connection failed
Mar 8 10:00:05 server app[5678]: ERROR Unable to reach API endpoint

βœ… 19. Check Failed Systemd Services

systemctl --failed

Use Case: Identify failed services after reboot or update.
Sample Output:

UNIT           LOAD   ACTIVE SUB    DESCRIPTION
nginx.service  loaded failed failed The Nginx HTTP server
mysql.service  loaded failed failed MySQL Database Server

βœ… 20. View Recent Service Logs

journalctl -u nginx --since "1 hour ago"

Use Case: Investigate NGINX issues from recent logs.
Sample Output:

Mar 8 09:00:01 server nginx[1234]: [warn] 12 worker_connections are not enough
Mar 8 09:05:22 server nginx[1234]: [error] timeout connecting to upstream server

βœ… 21. Show System Boot Time

who -b

Use Case: Verify last system reboot time.
Sample Output:

system boot  2025-03-08 07:32

βœ… 22. Count Number of Established Network Connections

ss -s

Use Case: Quickly assess network connection health.
Sample Output:

Total: 100 (kernel 130)
TCP:   80 (estab 60, closed 5, orphaned 2, timewait 8)
UDP:   20

βœ… 23. Show All Cron Jobs

crontab -l

Use Case: Verify or audit scheduled jobs for a user.
Sample Output:

0 2 * * * /usr/local/bin/backup.sh
15 3 * * 1 /usr/local/bin/log_rotate.sh

βœ… 24. Show Kernel Messages

dmesg | tail -n 10

Use Case: Quickly check recent hardware or driver issues.
Sample Output:

[ 1234.5678] usb 1-1: USB disconnect, device number 3
[ 1234.7890] EXT4-fs (sda1): re-mounted. Opts: errors=remount-ro

βœ… 25. Check Open Files by Process

lsof -p [pid]

Use Case: Inspect file/resource usage of a process.
Sample Output:

COMMAND PID  USER  FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   1234 root  txt  REG  8,1    123456   1234 /usr/sbin/nginx

βœ… 26. Show Top Network Consumers

nethogs

Use Case: Identify processes using the most network bandwidth.
Sample Output:

PID  USER  PROGRAM          DEV  SENT     RECEIVED
1234 root  nginx            eth0 200 KB/s  500 KB/s
5678 user  firefox          eth0 150 KB/s  300 KB/s

βœ… 27. View Login History

last -a | head

Use Case: Track recent login attempts.
Sample Output:

user1   pts/0  192.168.1.10  Mon Mar  8 08:01 - 08:15  (00:14)
root    pts/1  10.0.0.5      Mon Mar  8 07:32 - down   (00:25)

βœ… 28. Show Active User Sessions

w

Use Case: See who is logged in and what they’re doing.
Sample Output:

USER   TTY      FROM          LOGIN@   IDLE   JCPU   PCPU WHAT
user1  pts/0    192.168.1.10  08:01    2:00   0.08s  0.08s -bash

βœ… 29. Check SELinux Status (if enabled)

sestatus

Use Case: Check if SELinux is enforcing or permissive.
Sample Output:

SELinux status:                 enabled
Current mode:                   enforcing

βœ… 30. Analyze Network Traffic by Host

sudo iftop

Use Case: Real-time bandwidth usage per host and protocol.
Sample Output:

192.168.1.10 => 93.184.216.34  1.20Mb  1.30Mb  1.40Mb
192.168.1.10 <= 93.184.216.34  1.00Mb  1.10Mb  1.20Mb

βœ… 31. View Top Processes Sorted by Memory Usage

top -o %MEM

Use Case: Identify memory-intensive processes.
Sample Output:

PID USER   PR  NI  VIRT   RES   SHR S %CPU %MEM TIME+ COMMAND
6789 user1  20   0  2.0g  1.5g  100m S  3.0  9.5  0:03.12 java

Explore past #60DaysOfDevOps challenges and their solutions here:

AWS Cloud Automation with Python & Boto3 (60 Days DevOps Challenge Day 7)
Advanced Python For DevOps (60 Days of DevOps Challenge Day 6 )
Python Basics for DevOps (60 Days of DevOps Challenge Day 5 )
Git Advanced - Rebase, Cherry-pick, Conflict Resolution (60 Days of DevOps Challenge: Day 4)
Git & GitHub - Basics, Branching, Merging, PRs (60 Days DevOps Challenge: Day 3)
Linux Shell Scripting & Automation (60 Days DevOps Challenge: Day 2)
Linux Basics - Commands, File System, Users & Permissions (60 Days DevOps Challenge: Day 1)
You may also like:

⚑ Quick Reference

Keep the momentum going β€” everything you need on LearnXOps in one place:

Share this post