• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

top Command Examples in Linux

by admin

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]

Listing the state of running processes.

top command examples in Linux

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.

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:

?

Filed Under: Linux

Some more articles you might also be interested in …

  1. dive: A tool for exploring a Docker image, layer contents, and discovering ways to shrink it
  2. How to Use rpm2cpio Command in Linux
  3. lvresize: command not found
  4. urxvt Command Examples in Linux
  5. How to install/remove/query/update RPM packages in Linux (Cheat Sheet)
  6. Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  7. doctum: A PHP API documentation generator
  8. How to use the ssh-keygen Command in Linux
  9. CentOS / RHEL : Resize (reduce) non-root EXT3/4 filesystem on non-LVM device (hard disk partition)
  10. hashid Command Examples

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright