Table of Contents
This tip is about the how to Use Linux top Command. So read this free guide, How to Use Linux top Command step by step. If you have query related to same article you may contact us.
How to Use Linux top Command – Guide
The top command allows users to monitor processes and system resource usage on Linux. It is one of the most useful tools in a system administrator’s toolbox and comes 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
As a Linux system administrator the top command is a commonly used command and in our daily tasks we use this command several times to show the resource usage by the processes on the server. This command helps us find out which process is using which system resources. The top command on Linux allows you to monitor the currently running processes and the system resources they are using. As a system administrator, it can be the most useful tool in your toolbox, especially if you know how to use the. The top utility comes pre-installed on all Linux distributions. This interactive command lets you customize how you check the process list, kill one, print the results to a file, and more.
How to Use Linux top command
The top command interface
To run the top command, open the Ubuntu command line, Terminal, and type the following:
You can open the Terminal from the System Dash or the shortcut Ctrl+Alt+T. Here’s what the output of the top command looks like. The top of the output shows statistics about processes and resource usage. The bottom displays a list of currently running processes. To navigate the list, you can use the arrow keys or the page up and page down keys. If you want to exit the command, you can press q or use the shortcut Ctrl+c which will end the command.
See top command Help
The top command help will provide 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
By default, the top command output is updated every 3 seconds. To change this range, 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
If you want the top command to display the processes running by a specific user, you can use the following syntax:
For example, the following command will display all processes that are running by root:
Highlight active processes in main output
When you press the z key while your top command is running, the currently active processes.
Visualize the Absolute Path of Processes
If you want to see the absolute path of running processes, press c key while top command 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
a very powerful feature of the top command is that you can kill processes running through it. This is especially useful when a process is unresponsive and you want to get rid of it. 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
Renice means 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
As mentioned above, you can exit the top command manually via q or ctrl+c. In case you want the top command to run only up to a specific number of output updates, you can use the following command:
Example:
If you type the following command in Terminal, the top command will remain active until 3 updates and will automatically terminate afterward.
Save the main command results to a text file
You can save the current state of your system for later use if you save the output of the top command to a text file. Here’s How to do that:
For example, the following command will save the output of the top command in a file called top.txt:
The file will be saved to the current user home folder. If you try to open the file through any of your text editors, the contents will look like this:
I opened the file through the nano editor by typing the following command:
Final note
I hope you like the guide How to Use Linux top Command. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends.