Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the js_composer domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/holhol2/public_html/wp-includes/functions.php on line 6121

How to Clear Screen in Linux

By holhol24 | April 8, 2024
clear-command-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-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-linuxblank-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:

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

Now, press CTRL+L.

blank-screen-of-terminal-in-linuxblank-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 ‘33[2J’, and it works very similar to the keyboard shortcut. For instance:

echo “Hi Prateek, this is a test message.”

echo -e “33[2J”

ansi-method-to-clear-screen-in-linuxansi-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-linuxblank-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. 

holhol24

I am a Linux server pro admin and enthusiast, an upcoming web developer, junior php developer. I am currently a content creator for Holhol24, I love to play with Linux and all other distributions of it. I loves working with computers and strongly believes in sharing knowledge. Follow me For more insight into what is happening in Tech.

Advertisement Share: Facebook Twitter WhatsApp

Deprecated: File Theme without comments.php is deprecated since version 3.0.0 with no alternative available. Please include a comments.php template in your theme. in /home/holhol2/public_html/wp-includes/functions.php on line 6121

Leave a Reply

Your email address will not be published. Required fields are marked *