20 Linux Top Command Examples made easy to remember

By | January 24, 2017

Linux “Top” command displays information about the Processor activity.It displays information related to cpu and memory used by the each process.Top Command provides real time view of System Performance.Name of the “Top” command suggests you that,it displays information around processes which uses more cpu and memory.Top command is great utility to find out why Server is crying with performance issues.

20 linux top command examples to remember made easy

20 linux top command examples to remember made easy

Let’s go by usages of “Top” Command.

Usage 1: Simply Enter “Top”

Tasks: 162 total, 1 running, 161 sleeping, 0 stopped, 0 zombie
 Cpu(s): 0.3%us, 0.7%sy, 0.0%ni, 99.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
 Mem: 1923392k total, 1821040k used, 102352k free, 198520k buffers
 Swap: 3145724k total, 8k used, 3145716k free, 1038272k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
 12339 root 20 0 310m 17m 14m S 0.3 0.9 11:17.61 vmtoolsd
 23469 root 20 0 15040 1260 936 R 0.3 0.1 0:00.20 top
 31339 root 20 0 79100 8572 5436 S 0.3 0.4 2:17.81 ccsmagtd
 1 root 20 0 19364 1548 1224 S 0.0 0.1 0:04.87 init

Screen refresh for every 3 second’s by default.It displays lot of information like cpu,mem,swap and pid and lot more.

Usage 2: Refresh screen output by 3 seconds,2 seconds or 0.5 Second.

While seeing the top command output press "d" key.It will ask you to enter time interval.
You can change the time interval required.

Usage 3: Sort “Top” output by Memory

While it is displaying the output as above press "M ",it will sorted by memory.

Usage 4: Sort “Top” output by cpu

While it is displaying the output as above press " P",it will be sorted by cpu.

Usage 5: Sort “Top” output by process id

While it is displaying the output as above press "N ",it will be sorted by process id.

Usage 6: Save “Top” output in the location “/root/.toprc.”

we can save the top output in the "/root/.toprc" at any movement by pressing "Shift + w "

Usage 7: exit top output while it is running.

while top command is showing the process output,one can exit by pressing "q" key

Usage 8: exit top output automatically after showing 20 times.

SLTMachine: # top -n 20

top output will be shown 20 times,After that it will automatically exit from the 
output window without pressing "q" key

Usage 9: Sort “Top” output by running time.

While it is displaying the output as above press " T ",it will be sorted by running time.

Usage 10: Sort “Top” output by in reverse order

while it is displaying the output press "R",it will display in the reverse order of the output.

Usage 11: Print top current version.

SLTMachine: # top -v

top: procps version 3.2.8
 usage: top -hv | -abcHimMsS -d delay -n iterations [-u user | -U user] -p pid [,pid ...]

Usage 12: only show the processes related to particular username.

SLTMachine: # top -u <username>

top -u root

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
 1124 root 20 0 0 0 0 S 0.3 0.0 0:07.73 flush-253:0
 12323 root 20 0 299m 10m 8876 S 0.3 0.6 6:52.23 wnck-applet
 23626 root 20 0 15040 1268 940 R 0.3 0.1 0:00.04 top
 1 root 20 0 19364 1548 1224 S 0.0 0.1 0:04.89 init
 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
 3 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
 4 root 20 0 0 0 0 S 0.0 0.0 0:01.38 ksoftir

Usage 13: If you want learn more help on the “Top” enter below command.

SLTMachine: # man top

Usage 14: Highlight the sorted columns with bold text

Press "x" to highlight the sorted columns while it is showing the output

Usage 15: Highlight the running process in top output.

Press "Z" to highlight the sorted columns while it is showing the output

Usage 16: print complete command of the process which is running in the top command.

Press "C" to to show the absolute path of the command of the each process which is showing the top output

Usage 17: Kill process which is showing in the top command output.

Press "K" to kill the process id which is showing in the top command output.It will ask you to enter process id to kill.

Usage 18: Sort “Top” output by “cpu utilization” by “Ctrl + P” key.

we can sort by "Cpu utilization" by pressing key "Ctrl + P" key.

Usage 19: change the priority of process.

change priority of a process by entering "r" key in top command.It is also called "renice" a process.

Usage 20: Print “Top” output in different colours.

while you are seeing the top output,Press Key "Z".output will start appearing in different colors.

If you have more “Top” command usages,Please mention here.It will help other readers of the “Linux Top command Usages”.

Happy Simply learners 🙂

The following two tabs change content below.

SRINIVAS DARIPELLI

Myself SRINIVAS DARIPELLI. I have 15+ Years of Experience in Programming worked on multiple technologies.Apart from it,I am a blogger, writer, editor, artist and dad 🙂 .I believe in reality.I love to share the Helpful things around the Technology. Feel free to connect with me

Leave a Reply