Linux users, especially Ubuntu or CentOS users, are generally accustomed to using the clear command or the Ctrl+l combination shortcut to clear the terminal screen. However, this is not really a clear screen, it just gives the illusion that people think the screen is empty. But when you scroll up with the mouse, you can still see the output left by the previous command operation. When dealing with a large amount of text, this situation can cause us trouble. There are many other ways to clear the screen on the web, but it is basically a variant of the clear command. So, how can you really empty the screen? Share my method below, also can go to e Mentor Network Learning Linux Video tutorial .
Recently found a command that can solve our problem completely.
printf "\033c" is exactly the order we need. It's really empty the terminal screen, and its functionality is similar to the CLS effect provided by CMD.EXE in DOS.
But what exactly does this command do? How does it work?
\033 = = \X1B = = = ESC
As a result, this command becomes C, which is the escape code for "full Reset (RIS)" in Vt-xxx. All of 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 is a built-in command in bash, with the priority of built-in commands being higher than other executable files.
We can also use another command, reset, which also clears the terminal screen, but we can still use the up and down keys to view the history commands. One drawback of this command is that it performs somewhat slowly, perhaps because it does not send the ESC C instruction, but the compatibility of this command is obviously better than the previous one.
The reset command is useful when your terminal controls the disorder. Have you ever encountered a situation where the input characters do not show up at the cursor position? When you hit the ENTER key, the new prompt does not appear on the new line, but instead appears in front of the old prompt. The reset command is to fix the problem. You can also use this command on Cygwin.
Is this method of command useful to you? To learn more about Linux, please pay attention to e-mentor Network Oh!
How to completely empty the terminal screen in a Linux system