top: The cool tool you didn’t know you had

One of the things I had planned when I “restarted” this site was to visit some of the diehard tools — the ones that you probably got for free when you installed your system — and learn to use them better.

The most obvious candidate for that kind of unjustified, overblown disabuse is probably top.

2013-01-15-solo-2150-top-00

I think most people learn about top very early in their Linux careers. In my case, it no doubt was the first system monitor I learned.

Unfortunately for top, there are so many (so, so many … 😯 ) rival monitors available that it quickly loses its luster.

top is no dullard though. With a little prodding, it actually becomes quite lovely. Let’s get started.

First, we should follow the example of the man page, which says explicitly at the outset … that h is for the help screen, and q is for quit. Remember that, and you’ll never need to panic. 🙂

You might know that pressing the greater-than and lesser-than symbols shift the sort column to the left or right. And you might know to press R to reverse the sort.

But did you know that top is not just black and white? Press z.

2013-01-15-solo-2150-top-01

Well looky there. A lovely salmon and burgundy theme. Looks like a wine bar on a Friday night.

If you press z again, that color scheme will revert to black and white. Press Z and you get something akin to a theming menu.

2013-01-15-solo-2150-top-02

You can focus your artistic impulses by selecting the part of the display you want to change, then picking a color. So s followed by 2 will change the summary data to green.

2013-01-15-solo-2150-top-03

Given time and inclination, you can invent any of a million garish color schemes.

2013-01-15-solo-2150-top-04

There, that’s awful. Press enter to commit, and return to the main display.

2013-01-15-solo-2150-top-05

Not as bad as I imagined it. Let’s continue.

top’s summary information can be toggled on or off. Use l, t and m to blink information in and out of view.

2013-01-15-solo-2150-top-06

Why is that useful at all? Mostly because, as you might realize if you skim through screenshots in obscure forums, the truly geeky always employ some sort of cryptic system status bar grafted to their desktop. One cannot claim geekhood without the cryptic system status bar.

It’s simple enough to fake geekhood though: Pin that abbreviated top in a little terminal in a corner, snap a screenshot and you too can join the ranks of the technophiliacs.

Now let’s really get things screwy. If you press f, you get a list of available fields. Enable or disable a few of those with the space bar, pick a sorting field with s.

2013-01-15-solo-2150-top-07

Press enter to commit, q to leave that menu, and now your top display is quite unique.

2013-01-15-solo-2150-top-08

Unique is a good word for that. 🙄

There are quite a few more tricks that we can get top to do. What you see by default is every task listed, whether it’s active or not. Press i to screen out all the idle tasks.

2013-01-15-solo-2150-top-09

Sorry, I had to dump that awful color scheme. My eyes hurt almost as much as my artistic sensibilities.

Now press V for “forest view,” which is to say, the branched process structure.

2013-01-15-solo-2150-top-10

Fun. You can also press c for a display of the entire command line used to spawn each process.

2013-01-15-solo-2150-top-11

Nice. Things are looking much more interesting. Now let’s really crack our knuckles.

If you were paying attention, when we adjusted the color and when we modified the fields, you may have noticed top showing a window title, probably “1:Def”. You can go back and check it now if you don’t believe me.

What we were doing was modifying one of four windows that top can display. Want to see them all at once? Press A.

2013-01-15-solo-2150-top-12

Four different windows, and if your eyes are sharp, you’ll see that they all display information a little differently.

Number 1 is Def. Two is named Job, 3 is Mem and 4 is Usr. You can probably intuit what each means.

By default we are modifying window 1 … the Default. Color changes, field changes, forest views — whatever, when you change it, you’re probably adjusting default.

How do we get to the other windows? Press g, and you will be asked for your selection.

2013-01-15-solo-2150-top-13

From there, you can modify any of the other windows you like, with no impact on earlier ones.

What if you don’t want the group? Press hyphen. The group disappears, and the window name in the upper left corner is no longer reversed.

2013-01-15-solo-2150-top-14

Press hyphen again to bring it back. Press A to return to single-window mode, remembering that your last selected group will now be the focus of your love and attention.

There are a couple of other small things worth trying before bringing this extremely long introduction to a close.

First, if I remember right, top refreshes by default every three seconds. Some of us are impatient and would like to see a quicker display. Press s for adjust the interval.

2013-01-15-solo-2150-top-15

Careful you don’t overload your Pentium trying to … watch the load. 🙄

top allows you to renice a program — for the uninitiated, that means to adjust its priority in the mix. Press r and you get the chance to emphasize the toys you love, and neglect those you don’t.

2013-01-15-solo-2150-top-16

Remember that nice values are a little counterintuitive. Take a look at the man pages for top if you’re not sure you’re getting the results you want.

Finally, let’s kill something. The k key in top allows you to send a program into the ether, never to be heard from again.

2013-01-15-solo-2150-top-17

Confirm it and the target will be terminated … with extreme prejudice.

Note that for those last three commands, when you press the key, the display freezes. That allows you to read a program’s PID if needed, and enter the right target.

Last tip: All that setup and all those configurations are saved when you press the W key. Don’t lose all your hard work. 🙂

I wouldn’t call myself a top expert by any stretch. My hope here was just to show that some of the tools we glance past are just as customizable and interesting as the newcomers.

top does a lot of stuff that most people never know about, because it has a rather droll presentation and doesn’t do some of the things the new kids can.

But take a little time to learn about it and you’ll find all kinds of fun stuff. Where should you go next?

Well, to the man pages, of course. 🙂

25 thoughts on “top: The cool tool you didn’t know you had

    1. lotus

      He already reviewed htop and many other “tops”, the point of this to see the one we all have but few of us knew it had all these modificiations and options.

  1. tingol

    Wow! I’ve always installed htop as one of the first programs after installation but seeing what top can do I might even reconsider it! I’d love to see more of these “re-discoveries” in the future 🙂

  2. Pingback: Visto nel Web – 67 | Ok, panico

  3. Pingback: {hacker,reddit}-top: Monitoring at your pleasure | Inconsolation

  4. Pingback: dmesg: An old, new, cool tool | Inconsolation

  5. Pingback: dateutils: Making everything better | Inconsolation

  6. Pingback: iptstate: Top, for iptables | Inconsolation

  7. Pingback: rainbow: Color filtering in a different way | Inconsolation

  8. Pingback: screenify: A tetchy little tool | Inconsolation

  9. Pingback: split: And the curse of the asinine defaults | Inconsolation

  10. Pingback: wget: And that which wget begot | Inconsolation

  11. Pingback: collectl: System details, in detail | Inconsolation

  12. Pingback: colorwrapper: Quite obviously, the author had me in mind | Inconsolation

  13. Pingback: forkstat: Catching the small and the quick | Inconsolation

  14. Pingback: pscpug: Nothing to do with pugs | Inconsolation

  15. Pingback: xrestop: The irony is palpable | Inconsolation

  16. Pingback: xrestop: The irony is palpable | Linux Admins

  17. Pingback: iptstate: In the tradition of the *tops | Inconsolation

  18. Pingback: logtop: Kind of like a *top … for a logs | Inconsolation

  19. Pingback: ips: Intelligent process monitoring | Inconsolation

  20. Pingback: ips: Intelligent process monitoring | Linux Admins

  21. Pingback: netsniff-ng: More than I bargained for | Inconsolation

  22. Pingback: netsniff-ng: More than I bargained for | Linux Admins

Comments are closed.