Commands to Clear Linux Terminal

While using the terminal, it comes a time when the terminal screen needs to be cleared. The excessive commands and their outputs overflood the terminal, affecting the readability/understandability of the commands/outputs.

This post will list the methods to clear the Linux terminal with the following outline: 

Method 1: Using the “reset” Command

The “reset” command wipes out all the previous command executed in the terminal. It not only clears the terminal completely but also reinitializes it to default. For this task, simply type the “reset” command in the terminal:

$ reset

Press the “Enter” key to see the results:

The “reset” command has cleared every command from the terminal.

Method 2: Using the “clear” Command

Another frequently used way to clear the terminal is the “clear” command line tool. This command line tool does not require any flag or argument to perform this task as described below:

$ clear

After pressing the “Enter” key, the terminal will be definitely clear, which is verified below:

The above command has deleted all the commands from the terminal, including previous commands that can be accessed by pressing the upward key (i.e., scrollback buffer).

To keep saving the scroll backpack buffer, use the “-x(not clear scrollback)” flag with the “clear” command:

$ clear -x

Press the “Enter key” and then scroll the page up. You will see that the recently typed commands remain to save in the terminal as shown below:

The output shows all the presently executed commands and does not delete them.

Method 3: Using the “printf” Command

The user can also clear the terminal by typing the “ASCII” code. Although it is a complicated method because of the “ASCII” code. In this case, 

  • \033” : Specifies the ASCII code for starting the terminal.
  • c”: Uses to clear the terminal. 

Execute the “printf” command with the defined ASCII code in this way to clear the terminal:

Hit the “Enter” key to execute the above-highlighted command:

The terminal has been cleared and reinitialized to the default.

Alternative Method: Create an alias

To avoid typing the command again and again, we created “slv” as an alias for printf “\033c“:

$ alias slv='printf "\033c"'

When the alias is created, run the “slv” alias in the terminal as a command to clear the terminal:

$ slv

Once the “Enter” key is pressed, the terminal will clear along with the scrollback buffer as shown in the screenshot:

The terminal has been cleared after executing the “slv” alias.

Method 4: Using the “Ctrl+L” Shortcut Key

The user can also clear the terminal using the “Ctrl+L” shortcut key. This shortcut key slides up the commands/outputs from the current window and shows up an empty screen.

In the result, the terminal has been cleared, as verified in the next image:

Conclusion

Linux offers three built-in “reset”, “clear”, and “printf” command line tools to clear the terminal screen. The “reset” and “printf” commands reinitialize the terminal to the default. Apart from these commands, the user can also use the “Ctrl+L” shortcut key to perform this task. This guide has illustrated all possible commands to clear the Linux terminal.