How to Use Linux top Command – Guide

The Top command is a powerful tool that system administrators can use to monitor processes and system resource usage on Linux. It is one of the most useful tools in a system administrator’s toolbox and is pre-installed on every distribution. Unlike other commands like ps, it is interactive and you can browse the process list, kill a process, etc. The Top command is one of the basic commands to monitor server processes on Linux. The Top command shows all processes running on the server. It shows system information and process information like uptime, average usage, running tasks, no. of the logged in user, no. of CPU processes, RAM usage ..

The top command on Linux is a commonly used command that can be used to show the resource usage by the processes on the server. This command can help you find out which process is using which system resources. The top command is a great tool to use if you know how to use it. The top utility comes pre-installed on all Linux distributions, so it’s easy to use.

How to Use Linux top command

The top command interface

sudo top This will open a window that displays the current status of your computer. ..

To open the Terminal from the System Dash or the shortcut Ctrl+Alt+T, type: Terminal

See top command Help

The top command provides a list of options that you can use to customize the output and the functions you can perform while running the top command. To view help, just press the h key while the top command is running.

Set interval to refresh screen

To change the time range for the top command, press the d key while the top command is running. You can then enter the new time, in seconds, after which the most recent output is updated on the screen.

View processes for a specific user

user_name -p pid This will list all the processes running by the user “user_name” with the pid number at the top.

ps -ef | grep root This command will display all processes that are running by the root user. ..

Highlight active processes in main output

When you press the z key while your top command is running, all the active processes are displayed.

Visualize the Absolute Path of Processes

If you want to see the absolute path of running processes, press c key while top is running. In the following output, you can see that the command now displays the path of running processes in the Command column:

Kill a running process with the Top command

The top command can kill processes running through it. This is especially useful when a process is unresponsive and you want to get rid of it. To do this, press the k key while the top command is running. A prompt will ask for the PID you want to drop. Enter the required process ID by viewing it in the list and press Enter. The process and the corresponding application will close almost immediately.

Change Priority of a Process-Renice

To change the priority of a process, press the r key while the top command is running and enter the PID of a process whose priority you want to change.

Automatically exit top command after specific number of updates

top -n 5

This command will keep the current working directory open and show the number of refreshing attempts since last startup.

top

Save the main command results to a text file

To save the current state of your system for later use, you can use the top command to generate a text file. Here’s how to do that: ..

This command prints the contents of filename.txt for n number of intervals, starting at 0.

top -o top.txt ..

The file will be saved to the user’s home folder if they are logged in. If they are not logged in, it will be saved to the default user’s home folder.

nano ~/Desktop/file.txt I opened the file through the nano editor by typing the following command: To open a file in nano, type the following command: nano ~/Desktop/file.txt ..

Final note

This guide is about how to use the top command in Linux. If you have any questions about this article, please ask us. Additionally, please share your love by sharing this article with your friends.