How do I get top
to quit similarly to the way less
quits, that is, not leaving behind its output on the screen?
This is the version I have:
procps-ng version 3.3.9
How do I get top
to quit similarly to the way less
quits, that is, not leaving behind its output on the screen?
This is the version I have:
procps-ng version 3.3.9
When you start it like this ...
... the screen clears after exiting top with q.
This acts more like
less
:(
smcup
switches to a secondary screen where thetop
command is executed and when you quittop
rmcup
switches back to the normal screen)You could alias the top command to do that ( How do I create a permanent Bash alias? )
Ironically1, this was briefly the behaviour of
top
. In 3.3.8,top
did clear the screen, but not in versions past or since. See Red Hat bug #977561:Due to the bug report, Jim then fixed it to again not clear the output in 3.3.9.
top
has no options or configuration settings to control this, AFAICT, this is entirely hardcoded behaviour. You might want to file a feature request at https://gitlab.com/procps-ng/procps/issues/.Until then, you could
clear
manually like Rinzwind suggested, or usetput
like steeldriver suggests.Interestingly, the commit mentioned above also has a nice explanation of the command steeldriver suggested, because it is in fact the same as what was originally done in the code:
... which corresponds to the
tput smcup
andtput rmcup
commands.1 Obligatory xkcd.
The behavior you are looking for from less is built in to an alternative called htop. You can install it with:
Specifically, it switching to the alternate screen mode before starting preserving your original screen contents when you close htop. It also has a variety of other enhancements over procps's top. Once it's installed, you can just run it as a regular user:
You could use
watch
:It default to update every two seconds, use e.g.
-n1
for one second if you want to change this behaviour. To quitwatch
, press Ctrl+C instead of the usual Q.Another approach is opening a new terminal window, e.g. with
xterm
:This behaves exactly like
top
normally does, the window closes when you quittop
with Q and of course it leaves no output in the terminal you started it from. Add&
to the end of this command to start it in the background and immediately release the terminal again.As Rinzwind's answer points out, the
clear
command clearstop
output from the screen.After exiting
top
you can also use Ctrl+L to clear thetop
output from the screen. After either command though, you can still scroll up the screen to see the oldtop
output.To really clear the screen, such that the
top
output cannot be scrolled back to, use thereset
command:Another option to give that "fresh look" of a brand new session is by running an "ASCII splash screen" (if you have one). In my case I would run:
now
script calls weather, calendar (cal
) andtoilet
with fancy time.screenfetch
paints the Ubuntu logo and machine stats.