Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

clear

Clean the terminal screen (and, by default, the scrollback buffer).

Level
Everyday Linux
Group
Shell and help
Needs root
No
Package
ncurses

What it does

clear removes all text from the terminal window and puts the prompt at the top. It sends the right control codes for your terminal type (from the TERM variable).

Ctrl+L does almost the same: it clears the visible screen but usually keeps the scrollback. When the terminal shows strange characters after you printed a binary file, reset is stronger than clear.

How to write it

clear [-x] [-T TYPE] [-V]

Options 3

Most used

-x
Do not clear the scrollback buffer (only the visible screen).
-T type
Use this terminal type instead of $TERM.
-V
Show the version.

Examples 11

$ run as a normal user# run as root (or with sudo)

  1. 1Clear the screen

    clear

    The prompt moves to the top of the window.

  2. 2Clear the screen with the keyboard

    # press Ctrl+L

    Faster than typing clear. Works in Bash and most programs.

  3. 3Keep the scrollback, clear only the screen

    clear -x

    You can still scroll up to see older output.

  4. 4Clear the screen before a demo or a screen share

    clear && history -c

    Clean screen and no old commands with internal names or tokens.

  5. 5Fix a terminal that prints strange signs

    reset

    reset sets up the terminal again. Use it after you cat a binary file by mistake.

  6. 6Clear the screen at the start of a menu script

    clear; echo "1) status  2) restart  3) logs"; read -p "Choice: " c

    Each time the menu shows, the old output is gone.

  7. 7Refresh a simple status view every 5 seconds

    while true; do clear; date; systemctl is-active httpd sshd; sleep 5; done

    A tiny dashboard. watch does this better: watch -n5 'systemctl is-active httpd sshd'.

  8. 8Clear for another terminal type

    clear -T xterm

    Rarely needed: when $TERM is wrong for the terminal you use.

  9. 9Use the tput way in a portable script

    tput clear

    Same result; tput can also set colors and move the cursor.

  10. 10Clear the screen and the scrollback in a jump host session

    clear && printf '\e[3J'

    Some terminals keep the scrollback; the extra code removes it too. Good after showing secrets.

  11. 11Make an alias that clears and lists

    alias cls='clear; ls -l'

    Personal shortcut; put it in ~/.bashrc.

Watch out

  • clear does not remove anything from your shell history or from log files. It only cleans the window.
  • Some terminal programs keep the scrollback even after clear.

Tips to remember

  • Ctrl+L = fast clear. reset = repair a broken terminal.

Full manual

This page explains the command in simple words. The original manual has every detail.

In your terminal: man clear