Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Linux Command to Clear the Screen: clear and Shortcuts

· 5 min read · Home Tech

In this article
  1. How to clear a Linux terminal
  2. What clear actually does
  3. clear, Ctrl+L, and reset
  4. Clearing scrollback and terminal history
  5. Common problems and fixes
  6. Using clear in scripts and pipelines
  7. Frequently Asked Questions

The standard Linux command to clear the terminal screen is clear. Type it at the shell prompt and press Enter; to clear the display from the keyboard, Ctrl+L usually does the same thing in common shells such as Bash.

How to clear a Linux terminal

At a command prompt, enter:

clear

The command redraws the terminal so the visible area is blank and a fresh prompt appears. It does not delete files, erase command history, or stop running processes. You can also run it after another command by separating the commands with a semicolon:

ls; clear

That example lists the current directory and then clears the display, so the listing will no longer be visible. If you want to clear the screen before running a command, put clear first instead.

What clear actually does

A terminal is not simply a window showing text. It is a text interface that interprets control sequences, including instructions to move the cursor, change colors, and erase parts of the display. The clear program uses the terminal’s capabilities to request an appropriate screen-clearing operation.

In practice, this usually makes the current terminal view blank and places the cursor at the top. It generally does not wipe the terminal emulator’s scrollback buffer: older output may still be available by scrolling up. This distinction matters if your goal is merely to declutter the current view rather than remove earlier output from the window.

The command’s behavior can depend on the terminal type and its configuration. Unix-like systems commonly use the terminfo database to describe terminal capabilities. The TERM environment variable helps programs identify the kind of terminal in use, and an incorrect value can make screen-control commands behave unexpectedly.

clear, Ctrl+L, and reset

These options are related, but they serve different purposes:

  • clear is a command you run at the shell prompt to clear the visible terminal display.
  • Ctrl+L is a keyboard shortcut that commonly clears or redraws the screen in interactive shells. Its behavior depends on the shell and its configuration.
  • reset reinitializes the terminal more thoroughly. It is useful when output has left the display garbled or the terminal is acting as if it is in the wrong mode.

Use clear for routine cleanup. Avoid reaching for reset just to hide a few lines: it is meant to recover terminal state, not simply tidy the display. Depending on the terminal, resetting may affect screen contents and can take a moment to complete.

Clearing scrollback and terminal history

A frequent misconception is that clear securely erases everything previously displayed. Usually it only clears the visible screen. Many terminal emulator applications retain scrollback, so you can still inspect earlier output by scrolling upward.

Some terminal emulators recognize escape sequences that clear both the visible screen and scrollback, but the exact method is application-specific. Check the emulator’s documentation or menu for an option such as “Clear scrollback.” There is no single shell command guaranteed to remove scrollback in every terminal.

Command history is separate again. Bash, for example, can save commands to a history file, while other shells use their own history settings. Clearing the display does not clear that history. If you need to manage command history, use the facilities of your shell and understand that saved history, terminal scrollback, and screen contents are three distinct things.

Common problems and fixes

  • The display does not clear: Confirm that you entered clear in a shell prompt, not inside a program that has taken control of the terminal. Some full-screen applications manage the display themselves.
  • The screen becomes garbled: If text appears in odd positions or the terminal behaves strangely after a program exits unexpectedly, try reset. If the shell is still usable, press Enter first, then type reset and press Enter.
  • “TERM environment variable not set” appears: The terminal type may be missing in a minimal environment, container, or remote session. Programs that need terminal capabilities may not work correctly until the environment is configured. Do not set TERM to an arbitrary value; use a value supported by the terminal and available terminfo database.
  • You are using a graphical terminal: The shell command and the emulator’s own clear-screen or clear-scrollback controls are not necessarily identical. Look in the application’s menus or preferences for its specific behavior.

When connected over SSH, clear still works through the remote shell, but what remains in scrollback is determined by the terminal application on your local computer. Clearing the remote display does not erase a transcript or logging file that may have been recording the session.

Using clear in scripts and pipelines

You can include clear in a shell script when a clean display is useful before presenting an interactive menu or status screen:

#!/bin/sh
clear
printf 'System status\n'

However, scripts may run without an interactive terminal—for example, under a scheduler, in a build job, or with output redirected to a file. In those cases, clearing the screen is usually unhelpful, and terminal-control output may become clutter. A script can check whether standard output is connected to a terminal with [ -t 1 ]:

if [ -t 1 ]; then
    clear
fi

For general-purpose scripts, use terminal-control commands only when a person is interacting with the program and the output is actually a terminal.

Frequently Asked Questions

What is the Linux command to clear the screen?
Run clear at the shell prompt and press Enter.

What keyboard shortcut clears a Linux terminal?
Ctrl+L commonly clears or redraws the screen in interactive shells such as Bash. Shortcuts can vary by shell, terminal, and configuration.

Does clear delete my commands or files?
No. It clears the visible terminal display; it does not delete files, remove shell history, or cancel processes.

Why can I still see old output after using clear?
Your terminal emulator may retain scrollback. Scroll upward, or use its clear-scrollback feature if you want to remove older lines from the window.

What is the difference between clear and reset?
clear is for clearing the display. reset is for reinitializing a terminal that is behaving incorrectly or displaying garbled output.