This article is all about the commands, and keyboard shortcuts to clear screen in Linux.
Linux Commands

How to Clear Screen in Linux

Linux is full of commands that allow you to achieve every task with numerous commands. Having these text-based commands is handy; you can unleash the full potential of your Linux system. Moreover, the terminal is the most popular command line interface (CLI) for executing these commands.

While working in the terminal, the screen gets cluttered with various commands and their outputs. Hence, erasing everything from the terminal window is a basic yet essential task for users, especially those unfamiliar with the CLI. In this short article, we have included various methods to clear the screen in Linux

Clearing the screen is fundamental whether working in the terminal or accessing any remote server via SSH. There are three ways for it, so let’s take a look at all of them:

The clear Command

The clear is the most straightforward method to wipe the screen: 

clear

clear-command-in-linux

After executing the command, the system will immediately clear the terminal window, giving you a blank screen.

blank-screen-of-terminal-in-linux

The Keyboard Shortcut

If you prefer keyboard shortcuts over commands, use CTRL+L. Unlike the clear command, this shortcut does not delete any contents of your current terminal window. Instead, it scrolls down the window to make it appear like the screen has been cleared. For example:

echo "Hi Prateek"

keyboard-keyboard-shortcut-to-clear-screen-in-linux

Now, press CTRL+L.

blank-screen-of-terminal-in-linux

The ANSI Escape Sequences- Advanced Method

Advanced users or those proficient in terminal interactions can also use ANSI escape sequences to clear the screen. The escape sequence for this is ‘\033[2J’, and it works very similar to the keyboard shortcut. For instance:

echo "Hi Prateek, this is a test message."

echo -e "\033[2J"

ansi-method-to-clear-screen-in-linux

In this command, the ‘-e’ option instructs the shell to start interpreting the backslash escapes in the entered sequence. On execution, you’ll get the below result:

blank-screen-of-terminal-in-linux

Conclusion

Even a beginner in Linux must know how to clear a terminal screen to navigate efficiently in the CLI environment. This short tutorial contains three methods to do so: the clear command, the CTRL+L keyboard shortcut, and an ANSI escape sequence. The clear command and the keyboard shortcut are the primary approaches, whereas the escape sequence is just an addition for an advanced user. 

About the author

Prateek Jangid