Thoroughly clear terminal screens in CentOS

Source: Internet
Author: User

Linux users, especially Ubuntu or CentOS users, are basically used to clearing terminal screens by using the clear command or Ctrl + L combination shortcut keys. 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.

Many other methods to clear the screen can be found on the Internet, but they are basically variants of the clear command. So how can we truly clear the screen?

Coincidentally, I recently found a command that can completely solve our problem.

Printf "\ 033c" is the command we need. It truly clears the terminal screen, and its function is similar to the CLS provided by CMD. EXE in DOS.

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 "FullReset (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 is a built-in command in bash, which has a higher priority than other executable files.

We can also use another command, reset, which also clears the terminal screen, but we can still use the up/down key to view historical commands. One disadvantage of this command is that it is a little slow to execute, maybe because it does not send the ESCc command, but the compatibility of this command is obviously better than the previous one.

The reset command is useful when your terminal is out of control. 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? The reset command is used to fix this problem. You can also use this command on CYGWIN.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.