Commands · Command

CommandLinuxmacOS

top

top

Shows a continuously updating, live view of running processes ranked by resource usage (CPU by default), refreshing every few seconds.

// PLATFORM NOTES

Linux

`-o` sorts by field, `-u` filters to one user, `-n` limits to N refresh cycles then exits.

macOS

BSD-derived `top` uses different flags for the same jobs — `-o` still sets the sort key, but `-U` (capital) filters by user instead of `-u`, and `-l <number>` sets the sample count instead of `-n`.

// FLAGS

-oLinux/macOS: choose the sort field, e.g. CPU or memory
-uLinux only: filter to one user's processes
-UmacOS only: filter to one user's processes — macOS's equivalent of Linux's -u
-nLinux only: limit to N refresh cycles then exit
-l <number>macOS only: set the number of samples to take then exit — macOS's equivalent of Linux's -n

// EXAMPLE

top — opens the live process view; press q to quit, k to kill a process by PID.

// GOTCHA

top is interactive and takes over the terminal — running it in a script or piping its output requires batch mode (-b on Linux), otherwise it just hangs waiting for a terminal. The user-filter and sample-count flags also differ by platform: Linux uses -u/-n, while macOS's BSD-derived top uses -U/-l for the same two jobs — a flag copied straight from a Linux guide can silently do the wrong thing (or error) on a Mac.

// RELATED COMMANDS