Linux columns in top

Top Command — How to reduce the displayed Columns

Can we get specific column in a top command, for eg I’m interested in only the memory utilization and CPU usage column. How do I reduce the displayed columns of the top command to only the above two columns?

5 Answers 5

NOTE: Assuming you have this version of top (procps). You can check with this command:

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

procps is often the version of top included with Fedora/CentOS/RHEL and other variants.

Changing columns

If you look in the man page for top you’ll see a section titled: «2b. SELECTING and ORDERING Columns». There are keyboard shortcuts for toggling visibility for the different fields/columns.

 f,o . Fields/Columns: 'f' add or remove; 'o' change display order F or O . Select sort field . Move sort field: '' next col right 

You can use the key f while in top to get to a secondary screen where you can specify which columns should be toggled visible or not:

Current Fields: ANOPQRSTUVbcdefgjlmyzWHIKX for window 3:Mem Toggle fields via field letter, type any other key to return * A: PID = Process Id * W: S = Process Status * N: %MEM = Memory usage (RES) * H: PR = Priority * O: VIRT = Virtual Image (kb) * I: NI = Nice value * P: SWAP = Swapped size (kb) * K: %CPU = CPU usage * Q: RES = Resident size (kb) * X: COMMAND = Command name/line * R: CODE = Code size (kb) . 

There are more, these are just a sample. When you’re done toggling the columns the way you want, use the Esc to get out of the selection screen.

Читайте также:  Top linux вывести только cpu

Saving configuration

You can use the Shift + W to save your changes so they’re the defaults:

 W Write configuration file 

The file is stored here, $HOME/.toprc , and looks like this:

$ more .toprc RCfile for "top with windows" # shameless braggin' Id:a, Mode_altscr=0, Mode_irixps=1, Delay_time=1.000, Curwin=2 Def fieldscur=AEHIoqTWKNMBcdfgjpLrsuvyzX winflags=129016, sortindx=19, maxtasks=0 summclr=2, msgsclr=5, headclr=7, taskclr=7 Job fieldscur=ABcefgjlrstuvyzMKNHIWOPQDX winflags=63416, sortindx=13, maxtasks=0 summclr=6, msgsclr=6, headclr=7, taskclr=6 Mem fieldscur=ANOPQRSTUVbcdefgjlmyzWHIKX winflags=65464, sortindx=13, maxtasks=0 summclr=5, msgsclr=5, headclr=4, taskclr=5 Usr fieldscur=ABDECGfhijlopqrstuvyzMKNWX winflags=65464, sortindx=12, maxtasks=0 summclr=3, msgsclr=3, headclr=2, taskclr=7 

See section 5 of the man page for more details, «5. FILES».

Источник

How to reduce and/or add more columns or fields to top command in Linux (swap, memory, etc)

In this article I will show you the steps using which you can control the list of columns you would like to see with the top command.

By default we see the below columns when top is executed without any arguments

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
11584 root 20 0 116376 1012 844 R 99.9 0.0 18716:08 agetty
1 root 20 0 133792 4156 2552 S 0.0 0.0 0:38.09 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.04 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:01.31 ksoftirqd/0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
7 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0

Adding a new column

Here I would like to add one more field to monitor the » swap » memory usage per process
To do this, press » f » which will show you below list of options

Here if you see some of the options are bright white, these are the fields which are currently enabled by default, to which now we would like to add » SWAP » details

Читайте также:  Новое в линукс и убунту

so navigate to the row which contains SWAP as shown below

and press » space » bar to select the highlighted option. Once you hit » space » bar, the highlighted option should turn to bright white color similar to other default options.

To go back to the home screen of top, press » Esc »
So now as you can see, a new column with » SWAP » has appeared at the last column

Similarly you can add any other column from the list of fields

Removing an existing column

To reduce or remove a column also similar steps can be followed as explained above

Press » f » to go to the list of fields and navigate to the option which you would like to remove from the default top home screen

Press » space » bar to un-select the field, by doing this the colour of the field would turn back to normal white colour similar to all other disabled sections as shown below, here I disabled » RES » memory column, press » Esc » to go back

So now the same has vanished from top home screen.

Save the changes permanently

To save the changes what you have made, so that the same is active when you execute top next time
press » Shift+w «

Once you press the same, you should see the above line as shown in the screenshot. The changes will be saved under your home folder using which top was executed

Below is the content of my /root/.toprc

Читайте также:  Dns linux resolv conf

top’s Config File (Linux processes with windows)
Id:i, Mode_altscr=0, Mode_irixps=1, Delay_time=3.0, Curwin=0
Def fieldscur=¥¨³´»=ÃÃ
efghij ·º¹Ã
&’)*+,-.winflags=193844, sortindx=18, maxtasks=0, graph_cpus=0, graph_mems=0
summclr=1, msgsclr=1, headclr=3, taskclr=1
Job fieldscur=¥¦¹·º(³´Ã
efghij »½@ )*+,-./0winflags=193844, sortindx=0, maxtasks=0, graph_cpus=0, graph_mems=0
summclr=6, msgsclr=6, headclr=7, taskclr=6
Mem fieldscur=¥º» ghij*+,-./0125689FGHIJKLOPQRSTUVWXYZ[]^_`abcdeff
winflags=193844, sortindx=21, maxtasks=0, graph_cpus=0, graph_mems=0
summclr=5, msgsclr=5, headclr=4, taskclr=5
Usr fieldscur=¥¦§¨ª°¹·ºÃ
efghij Ã
)+,-./12winflags=193844, sortindx=3, maxtasks=0, graph_cpus=0, graph_mems=0
summclr=3, msgsclr=3, headclr=2, taskclr=3
Fixed_widest=0, Summ_mscale=0, Task_mscale=0, Zero_suppress=0

I hope the article was useful.

Источник

Оцените статью
Adblock
detector