top Command Guide
top provides a real-time view of system processes and resource usage. Learn how to monitor your system effectively.
7 min read•Last updated: 2024
Dai Aoki
CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm
Quick Reference
Basic
topLaunch toptop -u userSpecific usertop -p PIDSpecific processInteractive
qQuitkKill processrRenice processDisplay
MSort by memoryPSort by CPUcShow full commandOptions
-d 5Refresh every 5s-n 1Run once (batch)-bBatch modeDownloadable Image Preview
Failed to generate preview
Basic Usage
Run top to see a real-time view of your system. Press q to quit.
bash
topUnderstanding the Display
Summary Area (Top Section)
The top section shows system-wide statistics:
Summary Lines
| Line 1 | Uptime, users, load average (1, 5, 15 min) |
| Line 2 | Tasks: total, running, sleeping, stopped, zombie |
| Line 3 | CPU: user, system, nice, idle, wait, hardware/software interrupts |
| Line 4 | Memory: total, free, used, buff/cache |
| Line 5 | Swap: total, free, used, available memory |
Process List Columns
Default Columns
| PID | Process ID |
| USER | Process owner |
| PR | Priority |
| NI | Nice value (-20 to 19) |
| VIRT | Virtual memory used |
| RES | Resident memory (physical) |
| SHR | Shared memory |
| S | Process state |
| %CPU | CPU usage |
| %MEM | Memory usage |
| TIME+ | Total CPU time |
| COMMAND | Command name or line |
Interactive Commands
While top is running, you can use these keyboard commands:
Navigation & Display
| h or ? | Show help |
| q | Quit top |
| Space | Refresh display immediately |
| d or s | Change update interval |
| l | Toggle load average display |
| t | Toggle task/CPU line display |
| m | Toggle memory line display |
| 1 | Show individual CPU cores |
Sorting & Filtering
| P | Sort by CPU usage |
| M | Sort by memory usage |
| T | Sort by time |
| N | Sort by PID |
| R | Reverse sort order |
| u | Filter by user |
| o | Add filter (e.g., COMMAND=nginx) |
| = | Clear all filters |
Process Control
| k | Kill a process (enter PID) |
| r | Renice a process |
Tip
Press
1 to see per-CPU usage, which is helpful for identifying CPU-specific bottlenecks.Command Line Options
bash
# Update every 5 seconds
top -d 5
# Show specific user's processes
top -u username
# Batch mode (useful for scripting)
top -b -n 1
# Show specific processes by PID
top -p 1234,5678
# Start with processes sorted by memory
top -o %MEMCustomizing the Display
Add/Remove columns
Press f to enter field management mode:
- Use arrows to navigate
- Press
dorSpaceto toggle display - Press
sto set sort field - Press
qorEscto exit
Save configuration
Press W to save current settings to ~/.toprc.
Color scheme
Press z to toggle color mode, or Z to customize colors.
Practical Examples
Monitor specific user
bash
top -u www-dataGet snapshot for scripts
bash
# Single iteration output
top -b -n 1 > system_snapshot.txt
# Top 10 CPU consuming processes
top -b -n 1 | head -17Monitor memory-intensive processes
bash
top -o %MEMWatch specific processes
bash
top -p $(pgrep -d',' nginx)Understanding Load Average
Load average shows system load over 1, 5, and 15 minutes.
- A load of 1.0 on a single-core means 100% utilization
- On a 4-core system, 4.0 means 100% utilization
- Load above your CPU count indicates processes waiting
Info
Compare load average to your CPU core count. Use
nproc to see how many cores you have.Alternatives to top
Alternative Tools
| htop | Interactive, colorful, easier to use |
| atop | Advanced monitoring with logging |
| btop | Modern resource monitor with graphs |
| glances | Cross-platform monitoring tool |
Summary
top is essential for real-time system monitoring. Key takeaways:
- Press
Pto sort by CPU,Mfor memory - Press
1to see individual CPU cores - Press
uto filter by user - Press
kto kill a process - Use
-bfor batch mode in scripts - Press
Wto save your configuration