Thoroughly clear the screen in CentOS
Linux users, especially Ubuntu or CentOS users, are basically usedclear
Command orCtrl+L
Combine shortcuts to clear the terminal screen. However, this operation does not actually clear the screen. It just gives people the illusion that the screen is cleared. However, when you scroll up with the mouse, you can still see the output from the previous command operations. When processing a large amount of text, this situation will cause us trouble.
There are many other ways to clear the screen on the Internet, but they are basicallyclear
Command variants. So how can we truly clear the screen?
Coincidentally, I recently found a command that can completely solve our problem.
printf “\033c”
It is exactly the command we need. It truly clears the terminal screen. Its functions are similar to those in DOS.CMD.EXE
ProvidedCLS
The results are similar.
But what exactly is this command? How does it work?
\033 == \x1B == 27 == ESC
As a result, this command becomes <ESC> c, which is the escape code in the VT-XXX that represents "Full Reset (RIS. All the terminals we use today are VT compatible, but if you find yourself using a very strange terminal, you may not be able to use this command.printf
It is a built-in command in bash. the built-in command has a higher priority than other executable files.
We can also use another command,reset
It also clears the terminal screen, but we can still use the up and down keys to view historical commands. One disadvantage of this command is that it is a little slow to execute, maybe because it has not been sentESC c
Command, but the compatibility of this command is obviously better than the previous one.
reset
Commands are useful when your terminal is in disorder. Have you ever encountered a situation where the input character cannot appear at the cursor position? When you press the Enter key, the new prompt does not appear on the new line, but in front of the old prompt?reset
The command is used to fix this problem. You can also use this command on CYGWIN.
[How-to-clear-terminal-screen-for-real]