Linux top: Here’s how to customize it
The top command – referred to below as Linux top – is a command on Unix and Unix-like systems such as Linux, which provides a dynamic real-time overview of a running system. It can display system summary information and a list of processes or threads currently managed by the Linux kernel.
The types of system summary information shown by the Linux top command and the order and size of information displayed are all user-configurable, and configuration changes can be made persistent across restarts.
Linux top command provides an interactive interface for process manipulation and a much more extensive interface for personal configuration that encompasses almost every aspect of its operation.
Table of Contents
Customizing Linux top command: Getting started
To run Linux top, type top from the command line. The Linux top command will, by default, look similar to the above screenshot. To customize, let’s begin with the memory scale by pressing E (shift + e) and e, then save changes using W (shift + w) and continue from there:
E: Extend-Memory-Scale in Summary Area – With this command, you can cycle through the available summary area memory scaling, which ranges from KiB (kibibytes or 1,024 bytes) through EiB (exbibytes or 1,152,921,504,606,846,976 bytes). If you see a `+’ between a displayed number and the following label, it means that top was forced to truncate some portion of that number. By raising the scaling factor, such truncation can be avoided.
e: Extend-Memory-Scale in Task Windows – With this command, you can cycle through the available task window memory scaling, which ranges from KiB (kibibytes or 1,024 bytes) through PiB (pebibytes or 1,125,899,906,842,624 bytes). While top will try to honor the selected target range, additional scaling might still be necessary to accommodate current values. If you wish to see a more homogeneous result in the memory columns, raising the scaling range will accomplish that goal. However, raising it too high is likely to produce an all zero result, which cannot be suppressed with the 0 (numeric not the letter) interactive command.
Next, when monitoring MySQL, Apache (or Nginx), and other threaded software. It can be helpful to add a column for the number of threads (nTH). You can do this using Fields-Management.
f | F: Fields-Management – These keys display a separate screen where you can change which fields are displayed, their order and also designate the sort field. I’ve added PPID (Parent Process Id), SWAP, and nTH.
Additional Linux top customization options
c: Command-Line/Program-Name toggle
This command will be honored whether or not the COMMAND column is currently visible. Later, should that field come into view; the change you applied will be seen.
f | F: Fields-Management
These keys display a separate screen where you can change which fields are displayed, their order and also designate the sort field. For additional information on these interactive commands,
see topic 3b. MANAGING Fields.
1: Single/Separate-Cpu-States toggle
This command affects how the `t’ command’s Cpu States portion is shown. Although this toggle exists primarily to serve massively-parallel SMP machines, it is not restricted to solely SMP environments. When you see `%Cpu(s):’ in the summary area, the `1′ toggle is On, and all CPU information is gathered in a single line. Otherwise, each CPU is displayed separately as: `%Cpu0, %Cpu1, …’ up to the available screen height.
b: Bold/Reverse toggle
This command will impact how the `x’ and `y’ toggles are displayed. It may also affect the summary area when a bar graph has been selected for CPU states or memory usage via the t or m toggles.
x: Column-Highlight toggle
Changes highlighting for the current sort field. If you forget which field is being sorted, this command can serve as a quick visual reminder, providing the sort field is being displayed. The sort field might not be visible because 1) there is insufficient Screen Width 2) the `f’ interactive command turned it Off. Note: Whenever searching or other Filtering is active in a window, column highlighting is temporarily disabled. See the notes at the end of topics 5d. SEARCHING and 5e. FILTERING for an explanation why.
y: Row-Highlight toggle
Changes highlighting for “running” tasks. For additional insight into this task state, see topic 3a. DESCRIPTIONS of Fields, the `S’ field (Process Status). Use of this provision provides important insight into your system’s health. The only costs will be a few additional TTY escape sequences.
z: Color/Monochrome toggle
Switches the `current’ window between your last used color scheme and the older form of black-on-white or white-on-black. This command will alter both the summary area and task area but does not affect the state of the `x,’ `y,’ or `b’ toggles.
i: Idle-Process toggle
Displays all tasks or just active tasks. When this toggle is Off, tasks that have not used any CPU since the last update will not be displayed. However, due to the granularity of the %CPU and TIME+ fields, some processes may still be displayed that appear to have used no CPU. If this command is applied to the last task display when in alternate-display mode, it will not affect the window’s size, as all prior task displays will have already been painted.
Z: Change-Color-Mapping
This key will take you to a separate screen where you can change the colors for the `current’ window or all windows.
W: Write-the-Configuration-File
This will save all of your options and toggles plus the current display mode and delay time. By issuing this command just before quitting top, you will be able to restart later in exactly that
same state.
You can continue to customize by reading the full Linux top man page using the command: man top, where you will find additional tips such as filtering Linux top command output by user. You can start top with top -u enteruser. You can also press h while viewing top to open the “Help for Interactive Commands” screen.
This post should serve as a quick guide to encourage you to explore customization, allowing you to get the most out of the Linux top command! Below, or at the very top of this post (using color), you can see the result of Linux top tweaks:
How to revert (reset) to default Linux top
mv ~/.toprc ~/.toprc_bk
rm ~/.toprc
Linux top alternatives
Of course, you’ll sometimes need to dig deeper than Linux top command. Especially for application performance monitoring, log analytics, etc. In which case, have a look at some more in-depth solutions in my 100 Top Server Monitoring & Application Performance Monitoring (APM) Solutions list. Also, check out these alternatives to Linux top: atop, glances and htop.
Conclusion
The Linux top command is a powerful tool for system monitoring and process management. Its ability to provide real-time data on system performance and running processes makes it indispensable for both system administrators and regular users.
The extensive customization options, as detailed in this article, allow users to tailor the command to their specific needs, enhancing its utility. Whether it’s changing the memory scale, adding new columns for thread count, or adjusting the display of CPU states, these customizations ensure that the Linux top command can provide the exact data needed in the most accessible way.
Remember, if ever you need to revert to the default settings, simply move or delete the configuration file as shown. Have fun and share your screenshots.
Reference: man top.
Published: September 8th, 2017 | Last updated: December 27th, 2023
Here’s a more htop-looking customized top as discussed here:
I’d like to learn more about how to use the Alternate display mode with the “A” hotkey.
I’ve found references to and explored the commands for working with it, and know the mechanics but I still have questions, such as:
Are the four sections just for me to have 4 different sortings or sets of fields displayed? Are the names of these 4 categories customizable? Can I use just 2 or 3 instead of all 4 at once? Can I use this to see real-time view of connections hitting my server? Similar to I think “net stat” or such on Windows?
So far what I’ve got isn’t very customized for any purpose, just exploring what I could do.
Hi @Cmdr
This is beautiful. I was not aware of this despite reading through man. Things are so much more complete when ideas are shared multidirectional. Thanks for sharing this!
Going to look into this as well!
Welcome to the forums; honored to have you!
Here is mine, window view, highlighted columns, sorted by highest or lowest values depending on whats needed. May be top is underrated.
Looks amazing! Welcome to the forums. Yes, for sure. top is so flexible. I’m guilty of not utilizing it to the full for many years.