This note summarizes first-pass Linux system inspection with top, free, df, du, and time.
Run:
topUseful fields:
PID: process IDUSER: process owner%CPU: current CPU usage%MEM: memory shareTIME+: accumulated CPU timeCOMMAND: command name or process command
Common interactive keys:
q: quitP: sort by CPUM: sort by memoryk: kill a process by PID after confirmation
Filter by user:
top -u usernameFor non-interactive snapshots, prefer:
ps aux --sort=-%cpu | head
ps aux --sort=-%mem | headfree -hImportant columns:
total: installed memoryused: memory in usefree: currently unused memoryavailable: a better estimate of memory available for new workbuff/cache: memory used for buffers and page cache
In most troubleshooting, available is more useful than free.
df -h
df -hT
df -iUse:
df -hfor readable capacity.df -hTto include filesystem type.df -ito detect inode exhaustion.
Low byte capacity and low inode capacity are different problems. A system can fail to create new files even when it still has free bytes.
Measure one directory:
du -sh /path/to/targetRank direct children:
du -h --max-depth=1 /path/to/target | sort -hrFind large files:
find /path/to/target -type f -exec du -h {} + | sort -hr | head -n 20df -hT
df -i
du -h --max-depth=1 /path/to/mount | sort -hr
find /path/to/mount -type f -exec du -h {} + | sort -hr | head -n 20The layers are:
dffinds the stressed filesystem.df -ichecks whether inode count is the real problem.dufinds the responsible subtree.findplusduidentifies large individual files.
Use time to measure a command:
time grep -R "ERROR" logs/Typical output includes:
- real elapsed time
- user CPU time
- system CPU time
This is useful when comparing two command forms, such as a broad recursive search versus a narrower targeted search.