Catalog / top Command Cheatsheet

top Command Cheatsheet

A comprehensive guide to the `top` command, covering process monitoring, system resource usage, and interactive commands for Unix-like operating systems.

Basic Usage

Starting top

To start the top command, simply type top in your terminal.

top

The display updates periodically, showing a snapshot of the system’s processes.

Understanding the Display

The top display is divided into two main sections:

  1. Summary Area: Displays overall system statistics.
  2. Task Area: Lists the processes being managed by the kernel.

Summary Area Fields

uptime

Shows how long the system has been running, the number of logged-in users, and the system load average.

Tasks

Displays the total number of tasks, along with their statuses (running, sleeping, stopped, zombie).

%Cpu(s)

Shows CPU usage statistics (user, system, idle, etc.).

KiB Mem

Displays memory usage (total, free, used, buffer/cache).

KiB Swap

Shows swap space usage.

Interactive Commands

Basic Commands

h

Displays the help menu.

q

Quits the top program.

1

Shows CPU usage per core (if supported).

Sorting Processes

Shift + p

Sorts processes by CPU usage (descending).

Shift + m

Sorts processes by memory usage (descending).

Shift + n

Sorts processes by PID (Process ID).

Shift + r

Reverses the sorting order.

Shift + t

Sorts processes by runtime.

Filtering Processes

u

Filters processes by username. Prompts for a username.

o

Adds a filter based on other fields. Prompts for a filter condition.

=

Clears all active filters.

Process Management

Killing Processes

k

Kills a process. Prompts for the PID of the process to kill and the signal to send (default is 15, SIGTERM).

Example

To kill a process with PID 1234 using the default SIGTERM signal:

  1. Press k.
  2. Enter 1234 when prompted for the PID.
  3. Press Enter to accept the default signal (15).

Changing Priority (Renice)

r

Renices a process. Prompts for the PID of the process and the new nice value.

Note

Only root can increase the priority (lower the nice value) of a process.

Example

To renice a process with PID 5678 to a nice value of 10:

  1. Press r.
  2. Enter 5678 when prompted for the PID.
  3. Enter 10 when prompted for the new nice value.

Advanced Features

Customizing Display Fields

f

Adds or removes fields from the task display. Allows you to customize which columns are shown.

d or s

Changes the delay time between screen updates in seconds. d prompts for the new delay, s toggles between preset delays. Default is 3 seconds.

Alternate Displays

V

Toggles forest view, showing parent-child relationships between processes.

c

Toggles the display of the full command path instead of just the command name.

Shift + l

Search for the string.

Command Line Options

top -u <username>: Starts top, displaying only processes owned by <username>.

Example:

top -u www-data

top -p <pid>: Starts top, displaying only the process with PID <pid>.

Example:

top -p 1234

top -n <number>: Exits after <number> iterations.

Example:

top -n 5

top -b: Batch mode operation