Since I’m doing a tech writing series, I thought I’d do something a little fun.
I know a lot of people prefer htop to top, on Linux, and that’s valid, but I
feel like a lot of folks ignore, or are unaware of, the awesome power of a lot
of the built in tools you get with a distro. I love top because you can create
custom views of resources, and make them portable in your .toprc. The thing
that bugs me the most about this, though, is that it can be hard to find this
kind of information in a single location. If you google ‘top’, you get a bunch
of pictures of the default screen, which is boring, and sometimes not very
Without getting too deep into my philosophy on that stuff, here’s a way that
you can make top look cool, but also make it a bit more functional.
(tl;dr: Open top and press these keys: z, x, c, V, m, t, y, 1, 0. If you want to get real crazy with the cheese wiz, also press b and i. Switch to alternate mode with ‘A’ and repeat that key sequence in each field. Move between fields with ‘a’ and ‘w’. Save your setup to .toprc with .’W’.)
Before we get started, you can write any changes to your .toprc config file with
‘W’. After you play with what we’re about to do a bit, make sure you save your
setup. It isn’t a huge pain to set it up every time, but it could be, if you
use top a lot.
Let’s get started by opening top. The first thing I do when I open a ootb,
unconfigured session of top is put that sucker in alternate mode with ‘A’. That
will give you four fields to work with instead of one. Each field can be treated
like it’s own separate top window. From what I know, you need to configure them
all independently. Once you’ve saved your setup, though, it’s done for good and
it’s portable, so we’ve got that going for us, which is nice.
You can move between the different fields with ‘w’ and ‘a’. In an almost vi like
way, you can use ‘g’, then 1-4 to move directly to a field. Toggle color in each
with ‘z’, or use ‘Z’ to customize the color for each field. Pressing ‘f’ will
drop you into a Field Management menu, where you can select the resource you’d
like to watch. You will notice that the summary field changes color to match the
field you’re currently in. I don’t change the colors of the four fields once
they’re set, because the summary field doesn’t change to match your settings. I
love having the color, though, because it makes it easier to differentiate
quickly between fields if you’re talking to someone about one of them.
Entering ‘1’ (that’s a one) will break your CPU stats out into the number of
cores you’ve got.
The ‘m’ key will cycle you through three different representations of memory
use. The first being text, the next two visual. Once that bar is open, you can
cycle through the various units of memory, like kibibytes or mebibbytes, using
the ‘E’ key. You can cycle through similar bars for CPU usage using the ‘t’ key.
Now your top is a bit easier to read, and looks a bit better. With color, one
can easily differentiate between the fields he/she needs to pay attention to.
If you want to filter out some of the noise, ‘0’ (that’s a zero) will toggle a
mode that suppresses zeros in most fields. That way you’re only seeing what’s
actually being used. On the other hand, ‘c’ will toggle truncated command mode,
so you can see more information about the commands on screen. If you’re really going for that htop look now, you can also use ‘V’ to enter forest mode, which will show you how processes are related to their parents. Using ‘x’ to highlight columns, then turning off bold in favor of reverse using ‘b’ looks pretty neat, too, and will show you very obviously what each field you’re watching is focused on.
So, now your top has four fields of different colors, you’re not seeing zeros,
and you’ve got sweet visual bars in the summary fields that show your resource
use at a quick glance. Write it with ‘W’, and you’re good to move your .toprc
wherever you want it.
There’s a lot more to top, but I think this is a great start beyond what I used
to do, which was pretty much just open the window and watch. It also means that
you’ll have access to a bit more information where you may not have an internet
connection, or repositories that have htop, etc. in them. It’s for cases like
these that I recommend learning the built in tools, like bash, vi, and top. They
may not always be useful for what you need, but they will always be there. Plus,
I think top looks really cool when you tweak it like this.
Know anything else about top that I didn’t mention? Leave it in a comment!