Your server is slowing down. Your laptop fans kick into overdrive. You open the terminal, but then what? Without the right commands, you’re just guessing. With them, you become a system surgeon — able to diagnose exactly what’s consuming your resources and fix it.
Linux gives you extraordinary visibility into what’s happening under the hood. Today, we’re exploring the commands that let you take control of your system’s heart: its disk, memory, and I/O subsystems.
The System Stack: A Quick Mental Model
Think of your Linux system as a restaurant. Memory is the prep station (fast but limited), disk is the walk-in cooler (huge but slow), and I/O is the serving line that connects them. Your job is to make sure nothing’s bottlenecked, nothing’s wasted, and everything flows smoothly. Let’s learn the commands that show you how well your restaurant is running.
Memory Management: Your System’s Working Memory
1. free — How Much RAM Do You Actually Have?
The simplest way to check memory usage:
free -h # Human-readable format
free -h -s 1 # Refresh every 1 second
The output shows total memory, used, free, and buffers/cache. Here’s the key insight: Linux uses “unused” memory for caching, which is actually good. Don’t panic if “free” shows a small number — that’s normal and efficient.
2. top — The System Dashboard
Your go-to tool for real-time system monitoring:
top # Interactive view
top -b -n 1 # Single snapshot
top shows CPU usage, memory consumption, and running processes sorted by resource consumption. Press M to sort by memory, P for CPU. Press q to quit.
3. htop — Top’s Cooler Cousin
More visually appealing and user-friendly:
htop
It’s not installed by default, but once you install it, you won’t go back. Color coding, scrolling, and killing processes is easier here.
4. ps — Peek at Individual Processes
List running processes with detailed information:
ps aux # All processes with details
ps aux | grep python # Find specific processes
ps -eo pid,ppid,cmd,%mem,%cpu # Custom columns
This is powerful for scripting and understanding process hierarchies (parent-child relationships).
5. pmap — Memory Layout of a Process
See exactly where a process is using memory:
pmap -x 1234 # Show memory breakdown for PID 1234
This reveals how much memory is allocated to heap, stack, libraries, and mapped files. Invaluable for debugging memory leaks.
6. vmstat — Virtual Memory Statistics
Monitor memory and swap activity:
vmstat 1 # Report every 1 second
vmstat 1 10 # Report 10 times
The output shows memory stats, page swaps, and I/O activity. High swap values mean your system is struggling — it’s using disk as emergency memory, which is slow.
Disk Management: Taming Your Storage
7. df — Disk Free Space
Check how much disk space is available:
df -h # Human-readable
df -h /home # Check specific mount point
Running out of disk space is a common silent killer. Monitor this regularly.
8. du — Disk Usage Deep Dive
Find out what’s actually eating your disk:
du -sh /home # Total size of /home
du -sh /home/* # Size of each subdirectory
du -sh * | sort -h | tail -10 # Top 10 largest items
The -s flag summarizes (no subdirectories), -h makes it human-readable. This command finds rogue log files and cache directories hogging space.
9. lsof — What’s Open?
See which files and sockets are open:
lsof | head -20 # First 20 open files
lsof /home/user/file.txt # Who's using this file?
lsof -p 1234 # Files open by process 1234
lsof -i :8080 # What's using port 8080?
This is a Swiss Army knife. It tells you what a process has open, helping you understand dependencies and conflicts.
10. iostat — I/O Performance
Monitor disk I/O performance:
iostat -x 1 # Extended stats, every 1 second
iostat -d -k 1 # Disk stats in kilobytes
Look for high %util (utilization) or iowait (CPU waiting on I/O). These indicate I/O bottlenecks. await shows average time for I/O operations—higher values mean slower disk response.
11. iotop — Top for Disk I/O
See which processes are hammering your disk:
iotop
Like htop but for I/O. Press o to show only processes doing I/O. This reveals if some background process is secretly destroying your disk performance.
12. fdisk and lsblk — Disk Partitions
See your disk layout:
fdisk -l # List all disks and partitions
lsblk # Tree view of block devices
lsblk -o NAME,SIZE,TYPE # Custom columns
lsblk is newer and more user-friendly. Use it to understand your disk structure before any partition operations.
System-Wide Performance Monitoring
13. dmesg — Kernel Messages
Read system logs (kernel boot and hardware messages):
dmesg | tail -20 # Last 20 lines
dmesg | grep -i error # Look for errors
When hardware fails or the kernel panics, dmesg is where the truth lives. Check here when weird things happen.
14. uptime — How Long Has It Been Running?
uptime
Shows system uptime and load averages. The three numbers represent average load over 1, 5, and 15 minutes. On a single-core system, a load of 1.0 means fully utilized; 2.0 means overloaded.
15. load average — Understanding System Pressure
The magic question: is my system overloaded? Compare the 1-minute load to your CPU core count:
nproc # Show number of CPU cores
uptime # Show load averages
If your load average (1-minute) is higher than your core count, your system is overloaded.
16. sar — System Activity Report
Historical performance data (if installed):
sar -u 1 5 # CPU usage, 1-second intervals, 5 times
sar -r 1 5 # Memory usage
sar -b 1 5 # I/O activity
sar tracks system activity over time. It's invaluable for identifying patterns and recurring bottlenecks.
Advanced Memory Insights
17. proc Filesystem — The Source of Truth
Everything the kernel knows is exposed here:
cat /proc/meminfo # Detailed memory breakdown
cat /proc/cpuinfo # CPU information
cat /proc/[PID]/status # Details about a process
/proc isn't a real filesystem—it's the kernel talking to you. Understanding /proc/meminfo reveals buffers, caches, and memory pressure.
18. smem — Smart Memory Reporting
Shows actual memory used by processes (accounting for shared libraries):
smem -sort rss # Sort by resident memory
This is more accurate than ps for understanding true memory consumption.
I/O Deep Dive
19. blktrace — Trace Block I/O
Advanced tool for profiling disk I/O patterns:
blktrace /dev/sda -o trace_data
blkparse trace_data
This shows you exactly what I/O operations hit your disk — useful for optimization.
20. fio — Disk Benchmark
Test your disk performance:
fio --name=randread --ioengine=libaio --iodepth=32 \
--rw=randread --bs=4k --direct=1 --size=1G --numjobs=4
Generates realistic I/O workloads to measure actual disk performance under stress.
Putting It All Together: A Performance Investigation
Your system is slow. Here’s the diagnostic workflow:
- Check overall health: Run
uptimeand look at load averages - Find the culprit process: Use
toporhtopto identify what's consuming resources - Memory pressure? Run
free -handvmstat 1to check for swap activity - Disk space issue? Use
df -handdu -sh /to find space hogs - I/O bottleneck? Run
iostat -x 1to see if disk is saturated - Process details: Use
pmapandlsofon the problematic process - Kernel insights: Check
dmesgfor hardware errors or OOM killer activity - Historical patterns: Review
sarlogs to see if this is recurring
The Real Skills
Knowing these commands is half the battle. The real skill is understanding what the numbers mean. When you see swap activity, you know memory is overcommitted. When you see high %iowait in top, you know the CPU is waiting on disk. When you see many processes in D state (uninterruptible sleep), something is seriously wrong with I/O.
Practice and Intuition
Start by running these commands on your system right now. Get a baseline. Then run them again tomorrow, next week, and next month. You’ll develop intuition about what “normal” looks like for your system. That intuition is worth more than memorizing flags.
The terminal might look intimidating, but these commands transform you from someone who gets frustrated with slowness into someone who diagnoses and fixes it. You become the person who keeps systems running smoothly.
That’s the power of understanding your system at this level.