Terminal GuideTerminal Guide

top Command Guide

top provides a real-time view of system processes and resource usage. Learn how to monitor your system effectively.

7 min readLast updated: 2024
Dai Aoki

Dai Aoki

CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm

Quick Reference

Basic

topLaunch top
top -u userSpecific user
top -p PIDSpecific process

Interactive

qQuit
kKill process
rRenice process

Display

MSort by memory
PSort by CPU
cShow full command

Options

-d 5Refresh every 5s
-n 1Run once (batch)
-bBatch mode

Downloadable Image Preview

Failed to generate preview

Basic Usage

Run top to see a real-time view of your system. Press q to quit.

bash
top

Understanding the Display

Summary Area (Top Section)

The top section shows system-wide statistics:

Summary Lines

Line 1Uptime, users, load average (1, 5, 15 min)
Line 2Tasks: total, running, sleeping, stopped, zombie
Line 3CPU: user, system, nice, idle, wait, hardware/software interrupts
Line 4Memory: total, free, used, buff/cache
Line 5Swap: total, free, used, available memory

Process List Columns

Default Columns

PIDProcess ID
USERProcess owner
PRPriority
NINice value (-20 to 19)
VIRTVirtual memory used
RESResident memory (physical)
SHRShared memory
SProcess state
%CPUCPU usage
%MEMMemory usage
TIME+Total CPU time
COMMANDCommand name or line

Interactive Commands

While top is running, you can use these keyboard commands:

Navigation & Display

h or ?Show help
qQuit top
SpaceRefresh display immediately
d or sChange update interval
lToggle load average display
tToggle task/CPU line display
mToggle memory line display
1Show individual CPU cores

Sorting & Filtering

PSort by CPU usage
MSort by memory usage
TSort by time
NSort by PID
RReverse sort order
uFilter by user
oAdd filter (e.g., COMMAND=nginx)
=Clear all filters

Process Control

kKill a process (enter PID)
rRenice 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 %MEM

Customizing the Display

Add/Remove columns

Press f to enter field management mode:

  • Use arrows to navigate
  • Press d or Space to toggle display
  • Press s to set sort field
  • Press q or Esc to 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-data

Get snapshot for scripts

bash
# Single iteration output
top -b -n 1 > system_snapshot.txt

# Top 10 CPU consuming processes
top -b -n 1 | head -17

Monitor memory-intensive processes

bash
top -o %MEM

Watch 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

htopInteractive, colorful, easier to use
atopAdvanced monitoring with logging
btopModern resource monitor with graphs
glancesCross-platform monitoring tool

Summary

top is essential for real-time system monitoring. Key takeaways:

  • Press P to sort by CPU, M for memory
  • Press 1 to see individual CPU cores
  • Press u to filter by user
  • Press k to kill a process
  • Use -b for batch mode in scripts
  • Press W to save your configuration

Related Articles