How to get a clean screen — on the command line
After some time using terminal sessions they can get a bit cluttered with previous commands and their output data streams. At other times, I want to continue using the terminal session, but for security reasons I want to clear the data off the screen. Sometimes I just like to clean my screen and start fresh. There are two commands that I use to do this.
I hate to say it, but I neglected to include either of these commands in my books because they’re so simple that they’re easy to overlook. So let me rectify that.
clear
The clear command is a simple command that does exactly what its name implies — it clears the screen. It’s always the first thing I do when the screen gets too cluttered.
And it seldom needs either of its three options. Only the -x option, which prevents clear from also emptying the scrollback buffer, is normally useful. Although I’ve never used it because the scrollback buffer is usually clogged with clutter as well.
Just enter the clear command to clean the screen. You’re left with a command prompt at the top of the terminal session.
$ clear
reset
Sometimes the clear command isn’t enough. This can occur for a number of reasons but the terminal emulator won’t respond to the clear command. Other symptoms might be that the command prompt or the cursor may not be displayed, or you can’t see what you’ve typed on the command line.
The cause of this is that the terminal emulator’s configuration has been corrupted. I’ve seen this occur on rare occasions when sending a binary data stream to STDOUT.
You should be careful with what you type if you can’t see what you’ve typed, because it’s actually being entered even if you can’t see it. So don’t type anything except the reset command.
The reset command reinitialize the terminal to its properly configured state.
$ reset
This also results in a command prompt at the top of the terminal session and an otherwise clean screen.
You can try either of these commands without harm except for erasing everything off the terminal session. Be sure to read the man pages for each of these commands for more information.