This is the part of our on-going series of commands in Linux. We have covered basic ls command and cat command. In this article, we are trying to explore top command which is one of the most frequently used commands in our daily system administrative jobs. top command displays processor activity of your Linux box and also displays tasks managed by kernel in real-time. It’ll show processor and memory are being used and other information like running processes. This may help you to take correct action. top command found in UNIX-like operating systems.

You might also be interested in following tutorials :
- Htop (Linux Process Monitoring) tool for RHEL, CentOS & Fedora
- Iotop (Monitor Linux Disk I/O) in RHEL, CentOS and Fedora
1. Display of Top Command
In this example, it will show information like tasks, memory, cpu and swap. Press ‘q‘ to quit window.
# top

2. Sorting with -O (Uppercase Letter ‘O’).
Press (Shift+O) to Sort field via field letter, for example press ‘a‘ letter to sort process with PID (Process ID).

Type any key to return to main top window with sorted PID order as shown in below screen. Press ‘q‘ to quit exit the window.

3. Display Specific User Process
Use top command with ‘u‘ option will display specific User process details.
# top -u tecmint

4. Highlight Running Process in Top
Press ‘z‘ option in running top command will display running process in color which may help you to identified running process easily.

5. Shows Absolute Path of Processes
Press ‘c‘ option in running top command, it will display absolute path of running process.

6. Change Delay or Set ‘Screen Refresh Interval’ in Top
By default screen refresh interval is 3.0 seconds, same can be change pressing ‘d‘ option in running top command and change it as desired as shown below.

7. Kill running process with argument ‘k’
You can kill a process after finding PID of process by pressing ‘k‘ option in running top command without exiting from top window as shown below.

8. Sort by CPU Utilisation
Press (Shift+P) to sort processes as per CPU utilization. See screenshot below.

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

10. Save Top Command Results
To save the running top command results output to a file /root/.toprc use the following command.
# top -n 1 -b > top-output.txt

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

12. Exit Top Command After Specific repetition
Top output keep refreshing until you press ‘q‘. With below command top command will automatically exit after 10 number of repetition.
# top -n 10
There are number of arguments to know more about top command you may refer man page of top command. Please share it if you find this article useful through our comment box below.
Can you explain use of options in this command.
@Madhav,
The
-n
option specifies the maximum number of iterations and-b
enables batch mode operation, which could be useful for sending output from top to a file.Nice article, but how to search and see specific process memory and CPU utilization?
@Khim,
I think you should read this article Find Top 15 Processes By Memory Usage in Linux
very nice Article…!!!
basically I want this output to a file.. for 10 mins..
top – 13:29:09 up 1 day, 20:30, 1 user, load average: 0.65, 0.70, 0.69
Tasks: 1022 total, 1 running, 1020 sleeping, 0 stopped, 1 zombie
%Cpu0 : 13.0 us, 2.7 sy, 0.0 ni, 84.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu1 : 49.3 us, 3.6 sy, 0.0 ni, 45.7 id, 0.3 wa, 0.3 hi, 0.0 si, 0.7 st
%Cpu2 : 2.0 us, 2.0 sy, 0.0 ni, 95.4 id, 0.0 wa, 0.3 hi, 0.3 si, 0.0 st
%Cpu3 : 7.6 us, 2.0 sy, 0.0 ni, 90.4 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu4 : 1.3 us, 2.3 sy, 0.0 ni, 96.0 id, 0.0 wa, 0.0 hi, 0.3 si, 0.0 st
%Cpu5 : 26.1 us, 2.6 sy, 0.0 ni, 70.3 id, 0.3 wa, 0.3 hi, 0.0 si, 0.3 st
KiB Mem : 41042384 total, 1621820 free, 6024132 used, 33396432 buff/cache
KiB Swap: 21946356 total, 21946308 free, 48 used. 9811332 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
34389 root 20 0 967380 57812 8156 S 91.7 0.1 243:41.66 java
4295 oracle 20 0 4517788 497680 9364 S 0.0 1.2 4:15.28 java
Hi All, is there a way to get top output for a given command only listing all CPU info also and write to a file..
@Jai,
Please go through this following article, that will explain how to save top command output to a file in Linux.
How to Save Top Command Output to a File