Useful Linux Top Command

This is part of our ongoing series of Linux commands. We’ve already gone over the ls and cat commands. In this article, we will look at the top command, which is one of the most commonly used commands in our day-to-day system administration tasks. The top command displays the processor activity of your Linux box as well as real-time tasks managed by the kernel. It will display the processor and memory usage, as well as other information such as running processes. This may assist you in taking corrective action—the most important command in UNIX-like operating systems.

1. Display of Top Command

In this case, it will display information such as tasks, memory, CPU, and swap. To close the window, press ‘q’.

# top

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

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

To return to the main top window with sorted PID order, press any key, as shown in the screen below. To exit the window, press ‘q’.

3. Display Specific User Process

Using the top command with the ‘u‘ option will display details about specific User processes.

# top -u tecmint

4. Highlight Running Process in Top

When running the top command, pressing the ‘z‘ option will display the running process in colour, which may help you identify the running process more easily.

5. Shows Absolute Path of Processes

When running the top command, press the ‘c‘ option to display the absolute path of the running process.

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

The screen refresh interval is set to 3.0 seconds by default, but this can be changed by pressing the ‘d‘ option while running the top command and changing it as desired.

7. Kill running process with argument ‘k’

You can kill a process after determining its PID by pressing the ‘k‘ option while running the top command without exiting the top window.

8. Sort by CPU Utilisation

To sort processes by CPU utilisation, press (Shift+P).

9. Renice a Process

The ‘r’ option can be used to change the priority of the Renice process.

10. Save Top Command Results

Use the following command to save the output of the top running command to the file /root/.toprc.

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

11. Getting Top Command Help

To get top command help, press the ‘h’ key.

12. Exit Top Command After Specific repetition

The top output will continue to refresh until you press the ‘q’ key. With the following command, the top command will exit after ten repetitions.

# top -n 10

Leave a Reply

Your email address will not be published. Required fields are marked *