Diagnostic Commands
Overview of Linux Diagnostic Commands
Diagnostic commands are essential tools for identifying, analyzing, and resolving system issues in Linux environments. These commands provide insights into system performance, resource usage, and potential problems.
$ uname -a
Linux ubuntu 5.15.0-75-generic #82-Ubuntu SMP Wed May 17 14:58:11 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
2. lsb_release - Distribution Details
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.2 LTS
Release: 22.04
Codename: jammy
1. top - Real-time Process Monitoring
$ top
Tasks: 258 total, 1 running, 257 sleeping, 0 stopped, 0 zombie
%Cpu(s): 2.0 us, 1.0 sy, 0.0 ni, 97.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
2. htop - Enhanced Process Viewer
$ htop
(Interactive process viewer with color-coded system resources)
Resource Diagnostic Commands
1. df - Disk Space Usage
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 20G 30G 40% /
2. free - Memory Usage
$ free -h
total used free shared buff/cache available
Mem: 15Gi 5.0Gi 8.4Gi 0.5Gi 1.6Gi 9.5Gi
Swap: 2Gi 0B 2.0Gi
Network Diagnostic Commands
1. ping - Network Connectivity
$ ping -c 4 google.com
PING google.com (172.217.16.142): 56 data bytes
64 bytes from 172.217.16.142: icmp_seq=0 ttl=117 time=10.123 ms
2. netstat - Network Statistics
$ netstat -tuln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
Diagnostic Command Workflow
flowchart TD
A[Start Diagnosis] --> B{Identify Symptom}
B --> |System Info| C[uname, lsb_release]
B --> |Performance| D[top, htop]
B --> |Resources| E[df, free]
B --> |Network| F[ping, netstat]
C,D,E,F --> G[Analyze Results]
G --> H[Resolve Issues]
Comprehensive Diagnostic Commands
Command |
Primary Purpose |
Key Options |
uname |
System Information |
-a (all details) |
top |
Process Monitoring |
-d (update interval) |
df |
Disk Space |
-h (human-readable) |
free |
Memory Usage |
-h (human-readable) |
ping |
Network Connectivity |
-c (count packets) |
netstat |
Network Statistics |
-tuln (TCP/UDP listeners) |
LabEx Diagnostic Tips
When working in the LabEx Linux environment, combine multiple diagnostic commands to get a comprehensive view of system health and performance.
Conclusion
Mastering diagnostic commands is crucial for effective Linux system administration. These tools provide deep insights into system behavior, helping you quickly identify and resolve potential issues.