Normally we use the
clear command or press “Ctrl + L” to clear the terminal screen in Linux. Although it works, in reality the screen is not cleared – only the previous output is shifted upwards outside of the viewable area. But what if the requirement is to actually clear the terminal screen?
In this article we will discuss the
reset command that makes this possible. The article will also focus on another critical scenario where this command helps.
The problem with “clear”
As I have already mentioned in the beginning, the
clear command is the most commonly used command when it comes to clearing the terminal screen in Linux, and to be honest, it does the job most of the time. However, the fact that it just shifts the previous output upwards could result in confusion at times.
For example, imagine a situation where you’re doing something really critical on the command line (such as monitoring network activity to detect a possible hacking attempt) that involves running a single or a set of commands again and again and using mouse scroll or PgUP and PgDown keys to compare/analyze the output.
Now, if you issue a
clear command in between to clear the screen, the chances of you committing a mistake are high as it’s sometimes hard to differentiate where the output of the previous command ends and that of the current command begins.
For example, the following screenshot (taken after scrolling the terminal window up a bit) shows the use of “Ctrl + L” while running the
ls -lart command again and again.
How “reset” solves the problem
If you take a quick look at the
reset command’s man page, you’ll see that it says the command eventually initializes the terminal – or better put, re-initializes the terminal – instead of just manipulating the position of output which
Keep in mind, however, that the
reset command does not have any effect on the state of the shell (bash), meaning it remains unaltered.
What else can “reset” do?
There are times when you accidentally try opening an executable file in the terminal window using the
cat command. Needless to say, the output produced is all garbage as the file in question is a binary file.
That’s not a problem in most cases, as you can press “Ctrl + C” to get your prompt back and move on with your work. But sometimes the operation (displaying the contents of a binary file) could even result in your command line prompt getting corrupt:
And anything you write is also displayed as garbage characters.
That’s usually because somewhere in the binary data there are some control sequences that are interpreted by the terminal as requests to change the character set used to draw. To restore things back to normal, just run the
Note: type the
reset command carefully as the characters displayed on the terminal will be garbage until the command is successfully executed.
To sum it up, the
reset command is your friend-in-need – from actually clearing the terminal screen to fixing the terminal display, it’s usually your last resort. To learn more about the command, I’d encourage you to go through its man page.
Image credit: reset