top: command not found

Like ps, the top command lists all processes running on a Linux system. It acts as a process management tool by enabling you to prioritize, sort, or terminate processes interactively. It displays a dynamic process status, reflecting real-time changes.

Syntax

The syntax of the top command is:

# top [options]

Different keystrokes within this tool execute various process management actions. Some of the frequently used command keys include the following.

Key Used To
Enter Refresh the status of all processes.
Shift+N Sort processes in the decreasing order of their PID.
M Sort processes by memory usage.
P Sort processes by CPU usage.
u Display processes belonging to the user specified at the prompt.
k Terminate the process for which you specify the PID.
r Renice the process for which you specify the PID.
q Exit the process list.

If you encounter the below error while running the top command:

top: command not found

you may try installing the below package as per your choice of distribution:

OS Distribution Command
Debian apt-get install procps
Ubuntu apt-get install procps
Alpine apk add procps
Arch Linux pacman -S procps-ng
Kali Linux apt-get install procps
CentOS yum install procps-ng
Fedora dnf install procps-ng
Raspbian apt-get install procps

top Command Examples

1. “top” command for one iteration:

# top -n 1

2. kill process without exiting “top”:

# top
--> then press k
--> then enter PID

3. To renice a process:

# top
--> then press r

4. “top” for specific user:

# top -u geekuser

5. “top” for specific process:

# top -p PID,PID...

6. To display the CPU’s:

# top
--> then press 1

7. Refreshing output of “top”:

# top
--> then press "spacebar"

To change the output update frequency, press d in interactive mode, and enter the time in seconds.

8. Highlight Running Processes in the Linux Top Command Output:

# top
--> then press z/b

9. Display Absolute Path of the Command and its Arguments:

# top
--> then press c

10. Executing Unix Top Command in Batch Mode:

# top -b -n 1

Useful when you want to capture the output in txt format.

11. Split Top Output into Multiple Panels:

# top
--> then press A

12. Toggle Top Header to Increase Number of Processes Displayed:

# top
then
-->     Press l – to hide / show the load average. 1st header line.
-->     Press t – to hide / show the CPU states. 2nd and 3rd header line.
-->     Press m – to hide / show the memory information. 4th and 5th line.

13. To save top command configuration changes:

# top
--> then press W

14. Do not show any idle or zombie processes:

# top -i

15. Sort processes by a field:

# top -o field_name

16. Show the individual threads of a given process:

# top -Hp process_id

17. Show only the processes with the given PID(s), passed as a comma-separated list. (Normally you wouldn’t know PIDs off hand. This example picks the PIDs from the process name):

# top -p $(pgrep -d ',' process_name)

18. Get help about interactive commands:

?
Related Post