Did You Know?
Donate to TecMint

We are pleased to announce our new TecMint Q/A section to submit your Linux questions

12 TOP Command Examples in Linux

Download Your Free eBooks NOW - 10 Free Linux eBooks for Administrators

This is the part of our on-going series of commands in Linux. We have covered basic ls command and cat command. In this article, we are trying to explore top command which is one of the most frequently used commands in our daily system administrative jobs. top command displays processor activity of your Linux box and also displays tasks managed by kernel in real-time. It’ll show processor and memory are being used and other information like running processes. This may help you to take correct action. top command found in UNIX-like operating systems.

Linux Top Command Examples

Linux Top Command Examples

You might also be interested in following tutorials :

  1. Htop (Linux Process Monitoring) tool for RHEL, CentOS & Fedora
  2. Iotop (Monitor Linux Disk I/O) in RHEL, CentOS and Fedora

1. Display of Top Command

In this example, it will show information like tasks, memory, cpu and swap. Press ‘q‘ to quit window.

# top
Linux Top Command

Linux Top Command

2. Sorting with -O (Uppercase Letter ‘O’).

Press (Shift+O) to Sort field via field letter, for example press ‘a‘ letter to sort process with PID (Process ID).

Sorting Process ID's with Top

Sorting Process ID’s with Top

Type any key to return to main top window with sorted PID order as shown in below screen. Press ‘q‘ to quit exit the window.

Sorting Process ID's

Sorting Process ID’s

3. Display Specific User Process

Use top command with ‘u‘ option will display specific User process details.

# top -u tecmint
Top with Specific User Processes

Top with Specific User Processes

4. Highlight Running Process in Top

Press ‘z‘ option in running top command will display running process in color which may help you to identified running process easily.

Top Process with Colorful

Top Process with Colorful

5. Shows Absolute Path of Processes

Press ‘c‘ option in running top command, it will display absolute path of running process.

Top with Specific Process Path

Top with Specific Process Path

6. Change Delay or Set ‘Screen Refresh Interval’ in Top

By default screen refresh interval is 3.0 seconds, same can be change pressing ‘d‘ option in running top command and change it as desired as shown below.

Top - Set Refresh Time

Top – Set Refresh Time

7. Kill running process with argument ‘k’

You can kill a process after finding PID of process by pressing ‘k‘ option in running top command without exiting from top window as shown below.

Top - Kill Process ID

Top – Kill Process ID

8. Sort by CPU Utilisation

Press (Shift+P) to sort processes as per CPU utilization. See screenshot below.

Top - High CPU Utilization

Top – High CPU Utilization

9. Renice a Process

You can use ‘r‘ option to change the priority of the process also called Renice.

Top - Renice Process

Top – Renice Process

10. Save Top Command Results

Press (Shift+W) to save the running top command results under /root/.toprc.

Top Command Save Results

Top Command Save Results

11. Getting Top Command Help

Press ‘h‘ option to obtain the top command help.

Top Command Help

Top Command Help

12. Exit Top Command After Specific repetition

Top output keep refreshing until you press ‘q‘. With below command top command will automatically exit after 10 number of repetition.

# top -n 10

There are number of arguments to know more about top command you may refer man page of top command. Please share it if you find this article useful through our comment box below.

Ravi Saive

Owner at TecMint.com
Simple Word a Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux.

Linux Services & Free WordPress Setup

Our post is simply ‘DIY’ aka ‘Do It Yourself, still you may find difficulties and want us to help you out. We offer wide range of Linux and Web Hosting Solutions at fair minimum rates. Please submit your orders by Clicking Here.

26 Responses

  1. There is a typo in “Kill running process with argument ‘d’” . It must be ‘k’

  2. Ashokkumar says:

    Thanks.
    Nice tutorial.
    I m recently joined as system engineer.
    Actually I dont know what top command performs, i have followed what you did in the screen. I got same result.
    Can you explain what is the purpose of this command?
    How do I identify any wrong(process) in the terminal?

    Thanks

    • Ravi Saive says:

      @AshokKumar – the top command is used to monitor real time running processes in Linux. It is used to identify which processes is utilizing high CPU or memory usage. so you can kill that process with top command as we mentioned above.

  3. Ravi says:

    I tried write the top results to file, but i am not able to read the data, data is not well organised.

  4. Moosh says:

    I use htop

  5. gigi says:

    don’t forget ps-aux

    • Vishal says:

      Does it support feature like filter such as sort by, renice a process, or such above features ?

      No, it does not support.

      I hope you are getting my point! :)

  6. ferdinandp says:

    htop here…

  7. rama Krishna says:

    Hi ravi,
    Very useful cmds , it will be very useful if you can describe top cmd output.

    ram

    • dennis says:

      Excellent – just what I needed, written in a way I could read what I needed, and act on it right away… Thank You!!!

  8. rama Krishna says:

    like what is swap , zombie, and paging etc.

  9. rama Krishna says:

    I am WebSphere Application Server Admin, looking forward to get help from you on linux

  10. Rose says:

    Very useful blog. Thanks for this.

  11. Sam says:

    Great explanation, hope you dont mind linking to your website. Thanks.

  12. Nithin says:

    Highlight Running Process in Top is not working , is mapping of the color required?.

    Thanks

    Nithin.

  13. sana says:

    thanks for sharing helping commands, its help all Linux system admin.

  14. simon says:

    Nice, good job.

  15. prashanth says:

    Hi,

    i have req like i need to get Total CPU consmued by all processes is for particular user:

    i have used command :
    ps -eo pcpu | grep fa1dev |awk ‘BEGIN { printf “Total CPU consmued by all processes is: ” } /^ *[0-9]/ { total_pcpu +=$1 } END { printf total_pcpu }’

    output i m getting like:Total CPU consmued by all processes is:

    can you please update me command

  16. Thanks for article. I love to use HTOP.

  17. SachinG says:

    To get Quick understanding : good explaination

  18. Panpic says:

    How do I see detail pid ? such as path of pid

  19. Aamir says:

    Thank You !!!!

  20. kiran varma says:

    Hi Ravi,

    Article is very good .

    One thing I didn’t see any difference when I tried this Sorting with -O (Uppercase Letter ‘O’

    If possible can you please explain a bit more .

    Thanks

Leave a Reply

This work is licensed under a (cc) BY-NC | TecMint uses cookies. By using our services, you comply to use of our cookies. More info: Privacy Policy.
© 2012-2014 All Rights Reserved.