In our previous articles, we have covered the basics of ls command and cat command. In this article, we are trying to explore the top command which is one of the most frequently used commands in our daily system administrative jobs.
The top command (table of processes) displays the processor activity of your Linux box and also displays tasks managed by the kernel in real-time. It also shows information about CPU and memory utilization of a list of running processes.
You might also be interested in the following tutorials :
- Htop – An Interactive Process Viewer for Linux
- Iotop – Monitor Linux Disk I/O Activity and Usage Per-Process Basis
- bmon – A Powerful Network Bandwidth Monitoring for Linux
- Find Top 15 Processes by Memory Usage in Linux
1. List All Running Linux Processes
To list all running Linux Processes, simply type top on the command line to get the information of running tasks, memory, cpu, and swap. Press ‘q
‘ to quit window.
# top

2. Sort Linux Processes by PID
To sort all Linux running processes by Process ID, press M
and T
keys.

3. Sort Linux Processes by Memory and CPU Usage
To sort all Linux running processes by Memory usage, press M
and P
keys.

4. Sort Linux Processes by Running Time
To sort all Linux running processes by running time, press M
and T
keys.

5. Display Linux Processes By Specific User
To display all user-specific running processes information, use the -u
option will list specific User process details.
# top -u tecmint

6. Highlight Running Process in Top
Press ‘z
‘ option will display the running process in color which may help you to identify the running process easily.

7. List Absolute Path of Running Linux Processes
Press ‘c
‘ option in running top command will display the absolute path of the running process.

8. Set Refresh Interval for Top Command
By default screen refresh interval is set to 3.0 seconds, the same can be changed by pressing the ‘d
‘ option in running the top command to set desired interval time.

9. Kill Running Linux Process Using Top Command
You can kill a process after finding the PID of the process by pressing the ‘k
‘ option in running the top command without closing the top window as shown below.

10. Sort Linux Processes by CPU Utilisation
To sort all running processes by CPU utilization, simply press Shift+P
key.

11. Renice a Linux Process
You can use the ‘r
‘ option to change the priority of the process also called Renice.

12. Check Linux CPU Cores
To list the load information of your CPU cores, simply press 1
to list the CPU core details.

13. Save Top Command Results in File
To save the running top command results output to a file /root/.toprc use the following command.
# top -n 1 -b > top-output.txt
14. List Linux Idle Processes
Press 'i'
to get the list of idle/sleeping processes.

15. Getting Top Command Help
Press the ‘h
‘ option to obtain the top command help.

16. Exit Top Command After Specific Repetition
The output of the top command keeps refreshing until you press ‘q
‘. With the below command, it will automatically exit after 10 repetitions.
# top -n 10
There is a number of arguments to know more about the top command, you may refer man page of the top command. Please share it if you find this article useful or share your thoughts using our comment box below.
much usefull and clear explanation of the command with screenshots..also simple and easy to understand
Can someone please help me to gather only the top 20 processes information from the top command into a file after each 60 seconds of interval?
@Victor,
Here is the article, that will list Top 15 Processes by Memory Usage with Top Command.
Excellent Ravi,
Thank you for you information..
Hi Ravi
Point 10 saving top’s output to a file saves it configuration instead.
Please suggest in that,correct it if its wrong.
PFB output.
RCfile for “top with windows” # shameless braggin’
Id:a, Mode_altscr=0, Mode_irixps=0, Delay_time=3.000, Curwin=0
Def fieldscur=AEHIOQTWKNMbcdfgjPlrsuvyzX
winflags=62777, sortindx=15, maxtasks=0
summclr=1, msgsclr=1, headclr=3, taskclr=1
Job fieldscur=ABcefgjlrstuvyzMKNHIWOPQDX
winflags=62777, sortindx=0, maxtasks=0
summclr=6, msgsclr=6, headclr=7, taskclr=6
Mem fieldscur=ANOPQRSTUVbcdefgjlmyzWHIKX
winflags=62777, sortindx=13, maxtasks=0
summclr=5, msgsclr=5, headclr=4, taskclr=5
Usr fieldscur=ABDECGfhijlopqrstuvyzMKNWX
winflags=62777, sortindx=4, maxtasks=0
summclr=3, msgsclr=3, headclr=2, taskclr=3
@Abishek,
Yes its just only saves top configuration, to save the top running output to a file use the following command.
This is very helpful. Is there a guide to definitions of all the top headers? i.e. PR, NI etc.
This was VERY helpful for my OCR Computing Controlled Assesment, thanks!
If server has multiple processor suppose (3) is CPU usage will show 300% in top command or consolidate under 100%, and How can we see individual CPU Usage if server has multiple processors
just hit “1”. It will break out the the various CPUs
Ravi, it’s good collection of examples. Each and every details covered. Want to see more of this kind of work
@Srinivas,
Thanks for finding these example top command useful, more to come stay tuned..
Thank you very much ! Very helpful and useful.
Now I use : top -u myUser
Hello, I was wondering if anyone could help me by evaluating the usefulness of the top command to a technician when using it with ps and kill in order to investigate a system that is misbehaving. Thank you.
@Prince,
I suggest you to read the following articles that shows how to troubleshoot Linux systems when things misbehave….:)
https://www.tecmint.com/audit-network-performance-security-and-troubleshooting-in-linux/
https://www.tecmint.com/linux-system-monitoring-troubleshooting-tools/
Hi Ravi,
Please suggest some good links for L3 level Linux admin troubleshooting info (interview purpose).
keep up the good work.