When using Linux, the top command is a useful tool for keeping an eye on what processes are active and how much of the system’s resources they are using. Having a real-time view of your Linux system’s activity will allow you to more easily identify resource-intensive programs and terminate them. In this tutorial, we’ll go through the top command in Linux and how to use it to get detailed information on the processes currently operating on your machine.

Basic Top Usage

To access Linux’s top tool, open a terminal and type top:


$ top

Here is an example of the results of the top command:

There are two parts to the output:

The resource utilization, including that of the CPU, RAM, and disk, is shown in the upper part.

The bottom part displays data about the currently active processes and information like process ID, username, and process name.

Filtering Specific Processes

To restrict the top output to a particular process, hit the O key and enter COMMAND=name. Here, the name denotes the name of the process.

As an illustration of system filtering, consider:

When you click ENTER, the “top” will restrict the results to just systemd processes.


You may emphasize the desired process while maintaining sight of the others. 


Use the key to look for the string you want to find.


I’ll give you an example:



Filtering User Processes

There is also the option to only see processes that were started by certain user in the “top” output.


The -u option followed by the user’s name accomplishes this.
Consider the following example:
top -u ubuntu

In this case, only processes belonging to the Ubuntu user would be seen.

Sorting Tasks Based on Their CPU Usage

Furthermore, we may order the results using the proportion of Cpu usage. 


To do this, use the SHIFT + P keyboard shortcut.
The results are arranged by increasing values.

Changing the Refresh Interval

In its default setting, the top will automatically update its display every three seconds. While the top is running, using the d key will allow you to change this setting.

Displaying the Binary’s Path

Hit the c key to see the path to the command that started a certain process:


Saving The Output to a File

Additionally, using redirection indicators, we can save the file’s output. for instance, to save the top data for 10 minutes,  you may type:

top -n 3 -b > top_data.log

You may specify the number of iterations to do before quitting using the -n option.

With the -b option, the top enter batch mode and keeps processing the output until the max number of iterations has been reached (as indicated by the -n option).

Last Word

To summarize, if you’re a system administrator or just curious about which programs are draining your computer’s resources, top is a useful tool. The top documentation is a great resource for anyone interested in learning more about the “top”.