Linux top command is more powerful and useful for a system administrator to analyze the system’s process and resource status and utilization. In this tutorial, you will learn uses of top command by discussing on various top command examples.
The syntax of the top command is straightforward, and you can use like another command.
You can found the more on top command to use in our Linux command top help and example guide.
Here, you can find the most useful and daily use of top command examples in the system administrator’s life.
Linux top command Examples:
Example 1: Display all running process’s current status
The top command is use to display all information about the process like tasks, memory, CPU, and swap after executing top command use ‘q’ to quit from the top window.
Example 2: Shorting output using “O” option (Uppercase letter ‘O’)
You can sort the top command output using any filed. To sort the output first need to press ‘Shift+O’ to get the sort field letter as shown below:
Now you can press any field key-value like ‘a’ letter is use to sort process with PID (Process ID) filed.
Example 3: Show a specific user’s process
You can execute the top command with ‘-u’ option to display the all running process for the specific user.
Example 4: Highlight running process in top output
You can display top command output in color, which helps you to identify the running process easily and to do this use the ‘z’ option while running the top console.
Example 5: Display the absolute path of a process
You can use the “c” option to display the absolute path of the running process while running the top command.
Example 6: Change or set screen refresh time while running top command
You can change the screen refresh time interval from default 3.0 seconds to any other value. To change the value press ‘d’ option while running top command and enter the new value, as shown below:
Example 7: Kill running process in top
While running the top command, you can kill any process. To kill the process first find the process id and press ‘k’ key in top running console and enter the process id, as shown below:
Example 8: Short top output as per CPU utilization
If you want to sort the process output in top command as per CPU utilization, you should press Shift+P key to sort processes as per the CPU usage, as shown below:
Example 9: Change the priority of a process in top
The change of priority of a process is called renice, you can renice the process by using ‘r’ key while running the top command, as shown below:
Example 10: Save top command output in a file
You can save the output of the top command into the file for future reference by using the following command:
Example 11: Use top command in a secure mode
You can start top with secure mode forced, even for root. This mode is use to get better control through the system configuration. To run the top command in secure mode use following command:
Example 12: Top command forest view
Forest view of the process is nothing; it shows the process in a parent-child hierarchy. Sometimes you need to check the process in forest view, and you can do it by using ‘v’/’V’ key while running the top command.
Example 13: Exit top command after specific repetition
When you type top command on the console, it keeps refreshing output until you press ‘q.’ suppose you want to auto exit top command after 20 repetitions you can use below command:
Example 14: Getting help in top command
If you are a little bit confuse to use the top command with an option where it supports the various number of option, you can check the purpose of all option, and it will help you to use the correct option with top command. To get this help, you can use the ‘h’ option with top.
Example 15: Show manual of top command
The ‘man’ command is use to check the documentation of any command, so the below command ‘man top’ will display the manual page or documentation for top command.