Jannah Theme License is not validated, Go to the theme options page to validate the license, You need a single license for each domain name.

How to Use the top Command in Linux? {11 Examples}


Linux, like a chef’s kitchen, has many different tools and commands with specific purposes. To ensure a smooth and efficient process, the chef coordinates these helpers, while the kernel manages resources and operations. Linux is also customizable, allowing users to personalize their experience. 

Our Linux chef manages a busy kitchen where the “top” command acts as a real-time monitor. It’s displayed on a large screen in the kitchen, showing you (the chef or user) what’s happening at that moment. You can see how busy each assistant (process) is, which ones are using the most “heat” (CPU), and which ones are taking up the most “space on the counter” (memory).

This is a great article to learn about that real-time monitor, aka the Linux top command. You are going to get every detail about this command, right from the overview to the examples. Get started now.

Overview of top command syntax and options 

The ‘top’ command in Linux works as a live dashboard for your computer. When you enter ‘top’ in the terminal, it displays all the essential information about your system’s real-time activity. You can see details about the CPU and memory usage of various programs, the duration your computer has been running, and a list of all the currently running programs. Moreover, you can use it to stop programs or get more specific details about certain parts of your system. Overall, this tool is useful for keeping an eye on your computer’s performance and managing its activities efficiently. The basic syntax of the Linux top command is listed below.

Overview of top command syntax and options 

The top command in Linux can be altered in many ways to get the desired display of information. Take a look at these options below.

  • -d [delay]: Sets the time delay between screen updates.
  • -b: Runs “top” in batch mode for scripting purposes.
  • -n [number]: Sets the number of iterations before “top” exits.
  • -p [PID(s)]: Monitors specific process IDs.
  • -c: Shows command lines and program paths.
  • -H: Displays individual threads.
  • -i: Enables case-insensitive searching.
  • -u [username]: Monitors processes by a specific user.
  • -U [username]: Filters by effective user ID.
  • -s [seconds]: Sets period for CPU statistics.
  • -w: Formats output to fit wide screens.
  • -Z: Highlights security context changes.
  • -E: Toggles memory scaling in summary.
  • -h: Shows the command’s help screen.

Also Read: Learn to use SCP Command in Linux (with Examples)

Top Command Examples

  1. Start top: Type “top” and press Enter to check your system’s current status.
  • Syntax: top
  1. Set Refresh Interval: Adjust how often “top” updates. For instance, “top -d 5” refreshes every 5 seconds.
  • Syntax: top -d [interval]
Top Command Examples
  1. Sort by CPU Usage: Open your terminal, type top, and press Enter. Once in the “top” interface, directly press “Shift + P” (capital P) on your keyboard.
  1. Sort by Memory Usage: Open your terminal and type “top” to access the system statistics and processes. Then, press “Shift + M” to sort processes by memory usage.
  1. Kill a Process: To terminate a specific process on your terminal, follow these steps: First, open your terminal. Once it’s open, type ‘top’ and hit Enter. This will allow you to access the Linux “top” interface. In this interface, you should be able to find the process that you want to terminate. Take note of its “Process ID” (PID). Next, press “k” on your keyboard and enter the PID of the process you want to terminate. Finally, press Enter to complete the termination process. Make sure to replace [PID]withl processs ID of the specific process you wish to terminate.
  1. Filter Processes:  To customize the information displayed in the Linux top command, you can use the “Filter Processes” feature. Open your terminal and run the top Linux. In the “top” interface, press “Shift + F” to view the list of available fields. You can use the arrow keys to navigate and select or deselect the fields that you want to display or hide. Once you have made your selection, press “Enter” to apply it. This feature allows you to tailor the displayed information based on your preferences.
  1. Colorful Display: The “Colorful Display” in this command adds color to information for easy distinction between elements. Open the terminal, run the “top” command, and press “z” for colorful display.
  1. Display Threads: The “top” command’s “Display Threads” feature shows individual threads of running processes. To access it, run “top” in your terminal and press “H.”
  1. Show Process Paths: To reveal the full paths of the running processes and locate where each process executable is located in the file system, you can use the “Show Process Paths” feature in the “top” command. Open your terminal and type the “top” command. Once you are in the “top” interface, simply press the “c” key to display the full paths of the running processes.
  1. Display Process Tree:  Display Process Tree: The main aim behind using this approach is to ease out complex information. Although there is no direct way to display the tree structure in the Linux top command process, unlike the “pstree” option, you can partially do so by pressing “V” in “top.” This will let you switch between individual threads or summarize them under their associated processes.
  1. Save Settings: If you want the “top” command to remember certain display settings, sorting orders, or other customizations the next time you run it, you can use a helpful trick. However, keep in mind that there is no direct way to save settings in Linux top option. Instead, you will need to modify the ~/.toprc file to save your settings.

Also Read: Linux sed Command: From Basics to Advanced Usage

Final words

The top command is a real-time monitor available in Linux that helps you monitor your system’s activity. It shows you how much CPU and memory your system is using, which processes are running, and how well your system is performing. You can customize the view by changing how often it refreshes, sorting by CPU or memory usage, and choosing which fields to display. 

Although you can’t save your settings while it’s running, you can save customizations for later sessions by modifying the ~/.toprc file. The Linux top command is an essential tool for users and administrators because it helps you monitor processes and manage system resources efficiently. It provides valuable insights into your system’s performance and resource utilization.

Arpit Saini

He is the Director of Cloud Operations at Serverwala and also follows a passion to break complex tech topics into practical and easy-to-understand articles. He loves to write about Web Hosting, Software, Virtualization, Cloud Computing, and much more.

Related Articles