How to Clear Terminal in Linux {Clear Screen in Linux}

July 4, 2024

Introduction

The clear command is the go-to tool for clearing the terminal screen in Linux. Despite its effectiveness, clear does not reinitialize the terminal, which is sometimes necessary. Some alternative methods provide this option.

Read this tutorial to learn how to clear the terminal in Linux using different methods.

How to Clear Terminal in Linux

Prerequisites

  • A Linux system (this tutorial uses Ubuntu 22.04).
  • Access to the terminal.

How Do I Clear the Screen in Linux?

There are several methods to clear the screen in Linux. The following text elaborates on them.

Method 1: Clear the Screen in Linux via clear Command

The fastest way to clear the terminal screen in Linux is with the clear command. In most terminal emulators, like GNU, running clear without any arguments creates a blank slate screen:

clear
clear terminal output

Once executed, the command clears up the terminal:

terminal cleared

The command deletes everything, including the scrollback buffer. To keep the scrollback buffer, use clear with the -x argument:

clear -x
clear -x terminal output

The clear -x command clears the terminal and keeps the previous output. Scroll up or use the PgUp button to view it:

clear -x result

Additionally, the clear command does not reset the terminal. The shell state remains the same as before.

 Method 2: Clear the Screen in Linux via reset Command

Unlike clear, the reset command reinitializes the terminal and restores default settings. To clear the terminal with this command, run:

reset
terminal output for reset command

Executing reset takes a few moments to complete while clear shows effect instantly.

Method 3: Clear the Screen with Keyboard Shortcuts

Keyboard shortcuts also clear the terminal, depending on the terminal emulator.

In GNOME, the Ctrl + l shortcut has the same effect as clear -x. The shortcut clears the terminal while leaving the scrollback buffer:

ctrl + l terminal output

To access command output history, use PgUp or scroll up:

scrolling up

In some terminal emulators, an alternative is Ctrl + Shift + K. The command provides the same output as Ctrl + L.

Method 4: Clear Terminal via alias Command

Alternative methods for clearing the terminal are also more complicated. For instance, the \033 is the ASCII escape character used to start terminal control sequences. When followed by c, the command clears the terminal.

printf "\033c"
terminal output for printf "\033c"

The command clears the terminal screen, including the scrollback buffer.

clear terminal

To avoid typing numbers, create an alias for the command. For instance, set x as an alias for printf "\033c" with:

alias x='printf "\033c"'
alias x='printf "\033c"' terminal output

Once the alias is created, running x results in a clear terminal screen.

Conclusion

This article explained how to clear the terminal screen using a few different methods.

Next, check out the ultimate guide of all Linux commands everyone should know.

Was this article helpful?
YesNo
Sara Zivanov
Sara Zivanov is a technical writer at phoenixNAP who is passionate about making high-tech concepts accessible to everyone. Her experience as a content writer and her background in Engineering and Project Management allows her to streamline complex processes and make them user-friendly through her content.
Next you should read
How to Use the Linux history Command
May 30, 2024

The Linux bash shell saves a command history list, allowing you to review and reuse previous commands. Learn how to manage this list using the Linux...
Read more
14 Dangerous Linux Terminal Commands
November 17, 2021

It is always dangerous to run a Linux terminal command when you aren't sure what it does. This article lists 14 Linux commands that can have adverse...
Read more
How to Remove (Delete) a File or Directory in Linux
July 4, 2024

This article lists the most commonly used commands and tools to remove unwanted files and directories from your system...
Read more
Bash printf - How to Print a Variable in Bash
February 24, 2022

The printf command produces formatted text outputs in the terminal. This tutorial shows how to use the printf command to...
Read more