Uncategorized

Top Linux Command Usage with Examples – Serverwala

Introduction

Last updated on September 3rd, 2022

The ‘top’ Linux command is among the most often implemented commands when it comes to performing daily system administrative jobs. It enables you to keep a watch over processes and utilization of the system resource on the Linux system. Moreover, it also helps in displaying the processor activity of the Linux box, tasks managed by the kernel in real-time, information about the central processing unit, the memory usage of running processes, and much more. The Linux ‘top’ command is considered the most beneficial and interactive tool in a sysadmin’s toolbox. Also, you will find it already installed on every distribution. We have come up with this article to give you the details on how you can employ the ‘top’ command in numerous ways. Dive into the subsequent sections to acquire all the insights. 

First Check the Version of your Top 

The ‘top’ Linux command has been utilized since 1984. At present, there are various variants of the ‘top’ command in Linux available. Before, you move on to learn the Linux ‘top’ commands, ensure to check the version of ‘top’ you have on your system. You can check the version of ‘top’ Linux by entering the following command on your terminal window – 

top -v

You must note here that if your ‘top’ version is way behind 3.3.12, you might not acquire the support of all the features that you will come across in this guide. 

Read More: Learn to Create or Add User in Linux using ‘useradd’ Command

16 Linux Top Command Options

Check out below the significant 16 Linux top command options –

1. Listing all the Linux processes that are running

You have the possibility to view all the Linux processes that are running by simply entering the top on the command line. Enter the command as –

top

After entering this command, you will acquire the details of the tasks, CPU, swap, and memory running on your system. Moreover, afterward, you can press ‘q’ in order to quit the window. 

2. Sorting the Linux processes by PID

If you wish to sort all Linux processes that are running on the basis of Process ID, you will have to press M and T keys.

3. Sorting the Linux Processes by Memory and CPU utilization

If you wish to sort all the Linux processes that are running on the basis of Memory usage, you will have to press M and P keys.

4. Sorting the Linux Processes by Running Time

If you wish to sort all the Linux processes that are running on the basis of running time, you will have to press M and T keys.

5. Displaying the Linux Processes By Particular User

If you wish to display all the Linux processes that are running by a specific user, you will have to employ the -u option. This will help you obtain the specific user process details.

6. Highlighting the Running Process in top command

If you wish to highlight the running process on display in color, you can press the ‘z‘ option. This will help you in recognizing the running process easily.

7. Listing the absolute path of the Linux Processes that are running

If you wish to display the absolute path of the Linux Processes that are running, you have to press the ‘c‘ option with the top Linux command. 

8. Setting the refresh interval for the top command

In general, the screen refresh interval is 3.0 seconds by default. However, if you wish to change the screen refresh interval, you can do so by utilizing the ‘d‘ option in running the top command for setting the required interval time.

9. Killing the Linux process that is running

If you wish to kill the Linux process that is running, you need to first find out the PID of that particular process. After discovering the PID of the specific process, you need to press the ‘k‘ option with the top command while ensuring not to close the top window meanwhile.

10. Sorting the Linux processes by CPU Utilization

If you wish to sort the Linux processes that are running on the basis of CUP usage, you can directly press the Shift+P key.

11. To Renice a Linux process

If you wish to change the priority of any process, you can make use of the ‘r‘ option. Further, changing the priority of the process is also termed as Renice. 

12. Checking the Linux CPU Cores

If you wish to view the load information of the CPU cores, you can directly press 1 for the details of the CPU cores. 

13. Saving the top Command results in a file

If you need to save the running top command output into a file /root/.toprc, you can enter the command as-

top -n 1 -b > top-output.txt

14. Listing the Linux Idle Processes

If you need to view the Linux idle processes, you have to press the ‘i’ option for acquiring the list of idle/sleeping processes.

15. Receiving the top Command Help

If you need some help from the top command features, you can press the ‘h‘ option to obtain the same. 

16. Exiting the top Command after a particular recurrence

You must know that the output rendered by the top command goes on refreshing unless you press ‘q‘. You can sort this by setting a precise number of repetitions using ‘-n’. For instance, with the help of the following command, there will be automatic exit of the recurring output after 10 repetitions – 

top -n 10

Read More: Learn Using lsof Command in Linux with Examples – Serverwala

Final Words

You must have got the understanding by now that the ‘top’ Linux command is highly effective in monitoring and administering the processes on a Linux system. Apart from the essential ‘top’ commands Linux that you have learned in this guide, there are a lot of other arguments you can discover about the top command. For this, you can refer to the man page of the top command by entering the man top on your system. Furthermore, you can always reach out to us at Serverwala customer support for any queries or difficulties you might face. We are available through various communication modes for rendering prompt responses and accessible solutions. 

Get in Touch

Arpit Saini

He is the Director of Cloud Operations at Serverwala Cloud Data Centers Pvt Ltd and also follows a passion to break complex tech topics into practical and easy-to-understand articles. He loves to write about Web Hosting, Software, Virtualization, Cloud Computing, and much more.

Related Articles

Adblock Detected

Please consider supporting us by disabling your ad blocker