Master the Linux ‘top’ Command: A Comprehensive Guide for Beginners

Peter Hou
3 min readJun 5, 2023

--

This article provides a comprehensive guide on the top command in Linux, including its history, uses, parameters, and tricks. Ideal for beginners, this guide helps to effectively monitor system performance using the top command.

Instructions

This article aims to provide an in-depth understanding of the top command in Linux. It discusses the history, purposes, and how-to-use methods of top. Additionally, it explains commonly used parameters, provides other supported parameters, and shares some of the most common use cases and skills.

History

The top command has been a part of Unix/Linux systems since its early days and has been a vital tool for system administrators for real-time monitoring of system performance.

When and why to use it

The top command is used when there's a need to monitor system tasks and performance in real-time. It provides a dynamic view of the processes running on a system and is most useful for system debugging and performance tuning.

How to use it

The top command can be run without any options, which will provide a real-time dynamic view of the processes running on your system.

$ top
top - 15:58:13 up 6:52, 1 user, load average: 0.00, 0.01, 0.05
Tasks: 178 total, 1 running, 177 sleeping, 0 stopped, 0 zombie
%Cpu(s): 2.6 us, 1.3 sy, 0.0 ni, 96.0 id, 0.0 wa, 0.0 hi, 0.1 si, 0.0 st
KiB Mem : 2040204 total, 1161060 free, 530160 used, 346984 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 1285100 avail Mem

The commonly used parameters

  • -d Delay: Changes the delay between updates. The default is 3 seconds.
$ top -d 1
The output will be refreshed every 1 second.
  • -u User: Monitor tasks owned by a certain user.
$ top -u username
This will show only the processes owned by the specified user.

Other supported parameters

  • -b : Batch mode operation
  • -c : Command line/Program name toggle
  • -i : Idle Processes toggle
  • -n : Number of iterations limit as: n
  • -p : Monitor PIDs as: n
  • -s : Secure mode operation
  • -S : Cumulative time mode toggle
  • -U : Monitor by user as: n
  • -v : Version output

Most common use cases

One of the most common use cases of the top command is to monitor CPU and Memory usage in real-time, particularly when debugging performance issues.

$ top
Top command will show CPU and Memory usage.

The tricky skills

The top command can be used with 'pipe' and 'grep' for specific task monitoring.

$ top -b -n 1 | grep "Cpu(s)"
This command shows only the CPU usage.

What needs to be noted

Remember, the top command provides a real-time view and the displayed values can change rapidly as system processes and resources fluctuate.

Conclusion

Understanding the top command in Linux is critical for effective system monitoring and debugging. This powerful tool, when fully utilized, can provide valuable insights into how resources are being used in your system.

--

--

Peter Hou

I am a Senior Software Engineer and tech lead in a top tech company.