{"id":3262,"date":"2025-02-19T20:32:00","date_gmt":"2025-02-19T20:32:00","guid":{"rendered":"https:\/\/foghosting.com\/how-to-use-the-top-command-in-linux-11-examples\/"},"modified":"2025-02-19T20:32:00","modified_gmt":"2025-02-19T20:32:00","slug":"how-to-use-the-top-command-in-linux-11-examples","status":"publish","type":"post","link":"https:\/\/foghosting.com\/blog\/how-to-use-the-top-command-in-linux-11-examples\/","title":{"rendered":"How to Use the Top Command in Linux? {11 Examples}"},"content":{"rendered":"<div id=\"content\">\n<div role=\"main\">\n<div>\n<figure><\/figure>\n<\/div>\n<div>\n<h2><span id=\"Introduction\">Introduction<\/span><\/h2>\n<p>Linux, like a chef\u2019s 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.\u00a0<\/p>\n<p>Our Linux chef manages a busy kitchen where the \u201ctop\u201d command acts as a real-time monitor. It\u2019s displayed on a large screen in the kitchen, showing you (the chef or user) what\u2019s happening at that moment. You can see how busy each assistant (process) is, which ones are using the most \u201cheat\u201d (CPU), and which ones are taking up the most \u201cspace on the counter\u201d (memory).<\/p>\n<p>This is a great article to learn about that real-time monitor, aka the<strong> Linux top command<\/strong>. You are going to get every detail about this command, right from the overview to the examples. Get started now.<\/p>\n<h2><span id=\"Overview_of_top_command_syntax_and_options\">Overview of top command syntax and options\u00a0<\/span><\/h2>\n<p>The<strong> \u2018top\u2019 command in Linux <\/strong>works as a live dashboard for your computer. When you enter \u2018top\u2019 in the terminal, it displays all the essential information about your system\u2019s 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\u2019s performance and managing its activities efficiently. The basic syntax of the <strong>Linux top command<\/strong> is listed below.<\/p>\n<figure><\/figure>\n<p>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.<\/p>\n<ul>\n<li><strong>-d [delay]:<\/strong> Sets the time delay between screen updates.<\/li>\n<li><strong>-b:<\/strong> Runs \u201ctop\u201d in batch mode for scripting purposes.<\/li>\n<li><strong>-n [number]:<\/strong> Sets the number of iterations before \u201ctop\u201d exits.<\/li>\n<li><strong>-p [PID(s)]:<\/strong> Monitors specific process IDs.<\/li>\n<li><strong>-c:<\/strong> Shows command lines and program paths.<\/li>\n<li><strong>-H:<\/strong> Displays individual threads.<\/li>\n<li><strong>-i:<\/strong> Enables case-insensitive searching.<\/li>\n<li><strong>-u [username]:<\/strong> Monitors processes by a specific user.<\/li>\n<li><strong>-U [username]:<\/strong> Filters by effective user ID.<\/li>\n<li><strong>-s [seconds]:<\/strong> Sets period for CPU statistics.<\/li>\n<li><strong>-w:<\/strong> Formats output to fit wide screens.<\/li>\n<li><strong>-Z:<\/strong> Highlights security context changes.<\/li>\n<li><strong>-E:<\/strong> Toggles memory scaling in summary.<\/li>\n<li><strong>-h:<\/strong> Shows the command\u2019s help screen.<\/li>\n<\/ul>\n<p>Also Read: Learn to use SCP Command in Linux (with Examples)<\/p>\n<ol>\n<li><strong>Start top:<\/strong> Type \u201ctop\u201d and press Enter to check your system\u2019s current status.<\/li>\n<\/ol>\n<ul>\n<li>Syntax: top<\/li>\n<\/ul>\n<ol start=\"2\">\n<li><strong>Set Refresh Interval:<\/strong> Adjust how often \u201ctop\u201d updates. For instance, \u201ctop -d 5\u201d refreshes every 5 seconds.<\/li>\n<\/ol>\n<ul>\n<li>Syntax: top -d [interval]<\/li>\n<\/ul>\n<figure><\/figure>\n<ol start=\"3\">\n<li><strong>Sort by CPU Usage:<\/strong> Open your terminal, type top, and press Enter. Once in the \u201ctop\u201d interface, directly press \u201cShift + P\u201d (capital P) on your keyboard.<\/li>\n<\/ol>\n<ol start=\"4\">\n<li><strong>Sort by Memory Usage:<\/strong> Open your terminal and type \u201ctop\u201d to access the system statistics and processes. Then, press \u201cShift + M\u201d to sort processes by memory usage.<\/li>\n<\/ol>\n<ol start=\"5\">\n<li><strong>Kill a Process:<\/strong> To terminate a specific process on your terminal, follow these steps: First, open your terminal. Once it\u2019s open, type \u2018top\u2019 and hit Enter. This will allow you to access the <strong>Linux \u201ctop\u201d interface<\/strong>. In this interface, you should be able to find the process that you want to terminate. Take note of its \u201cProcess ID\u201d (PID). Next, press \u201ck\u201d 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.<\/li>\n<\/ol>\n<ol start=\"6\">\n<li><strong>Filter Processes:<\/strong>\u00a0 To customize the information displayed in the<strong> Linux top command<\/strong>, you can use the \u201cFilter Processes\u201d feature. Open your terminal and run the<strong> top Linux<\/strong>. In the \u201ctop\u201d interface, press \u201cShift + F\u201d 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 \u201cEnter\u201d to apply it. This feature allows you to tailor the displayed information based on your preferences.<\/li>\n<\/ol>\n<ol start=\"7\">\n<li><strong>Colorful Display:<\/strong> The \u201cColorful Display\u201d in this command adds color to information for easy distinction between elements. Open the terminal, run the \u201ctop\u201d command, and press \u201cz\u201d for colorful display.<\/li>\n<\/ol>\n<ol start=\"8\">\n<li><strong>Display Threads:<\/strong> The \u201ctop\u201d command\u2019s \u201cDisplay Threads\u201d feature shows individual threads of running processes. To access it, run \u201ctop\u201d in your terminal and press \u201cH.\u201d<\/li>\n<\/ol>\n<ol start=\"9\">\n<li><strong>Show Process Paths:<\/strong> 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 \u201cShow Process Paths\u201d feature in the \u201ctop\u201d command. Open your terminal and type the \u201ctop\u201d command. Once you are in the \u201ctop\u201d interface, simply press the \u201cc\u201d key to display the full paths of the running processes.<\/li>\n<\/ol>\n<ol start=\"10\">\n<li><strong>Display Process Tree:<\/strong>\u00a0 <strong>Display Process Tree:<\/strong> 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 <strong>Linux top command process<\/strong>, unlike the \u201cpstree\u201d option, you can partially do so by pressing \u201cV\u201d in \u201ctop.\u201d This will let you switch between individual threads or summarize them under their associated processes.<\/li>\n<\/ol>\n<ol start=\"11\">\n<li><strong>Save Settings<\/strong>: If you want the \u201ctop\u201d 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 <strong>Linux top option<\/strong>. Instead, you will need to modify the ~\/.toprc file to save your settings.<\/li>\n<\/ol>\n<p>Also Read: Linux sed Command: From Basics to Advanced Usage<\/p>\n<h2><span id=\"Final_words\">Final words<\/span><\/h2>\n<p>The top command is a real-time monitor available in Linux that helps you monitor your system\u2019s 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.\u00a0<\/p>\n<p>Although you can\u2019t save your settings while it\u2019s running, you can save customizations for later sessions by modifying the ~\/.toprc file. The<strong> Linux top command <\/strong>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\u2019s performance and resource utilization.<\/p>\n<\/p><\/div>\n<div>\n<div>\n<h3>Arpit Saini<\/h3>\n<p>\n\t\t\t\t\tHe is the Director of Cloud Operations at Fog Hosting 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.\t\t\t\t<\/p>\n<\/p><\/div><\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Linux, like a chef\u2019s 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.\u00a0 Our Linux chef manages a busy kitchen where the \u201ctop\u201d command<\/p>\n","protected":false},"author":3,"featured_media":3076,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[17],"tags":[],"class_list":["post-3262","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dedicated-servers"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/foghosting.com\/blog\/wp-json\/wp\/v2\/posts\/3262","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/foghosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/foghosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/foghosting.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/foghosting.com\/blog\/wp-json\/wp\/v2\/comments?post=3262"}],"version-history":[{"count":0,"href":"https:\/\/foghosting.com\/blog\/wp-json\/wp\/v2\/posts\/3262\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/foghosting.com\/blog\/wp-json\/wp\/v2\/media\/3076"}],"wp:attachment":[{"href":"https:\/\/foghosting.com\/blog\/wp-json\/wp\/v2\/media?parent=3262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/foghosting.com\/blog\/wp-json\/wp\/v2\/categories?post=3262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/foghosting.com\/blog\/wp-json\/wp\/v2\/tags?post=3262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}