top
Processes and system
Usage
topRedraws the process list every few seconds; its flags differ completely between platforms, so a single snapshot is `-b -n 1` on Linux and `-l 1` on macOS.
Common flags
| Flag | Meaning |
|---|---|
| -b -n 1 | Batch mode, one refresh, then exit: safe to pipe or log (Linux). |
| -p <pid> | Watch a single process (Linux). |
| -u <user> | Only one user's processes (Linux). |
| -o cpu | Sort by CPU on macOS; -o mem sorts by memory. |
| -l 1 | One sample and exit on macOS (the equivalent of -b -n 1). |
| P / M / k / q | Keys inside Linux top: sort by CPU, sort by memory, kill a PID, quit. |
Examples
top -b -n 1 | head -20A snapshot of the busiest processes, printable into a log (Linux).
top -o memLive list sorted by memory use (macOS).
top -p 1234Follow one process only (Linux).
What is running and what is eating the machine. Identifying it comes before killing it.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does top do?
Redraws the process list every few seconds; its flags differ completely between platforms, so a single snapshot is `-b -n 1` on Linux and `-l 1` on macOS.
Q. How do I type it?
top — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
6 are listed here; the full set is in man top. This command sits under Processes and system.
Related commands
man page: man top