sodcalculator

10 Tech How-To

Clear Terminal in Ubuntu & Linux: 5 Ways

Guide 10-12378 · Updated · Step by step

This guide shows you how to clear the terminal screen in Ubuntu and most other Linux distributions. You’ll learn the quick keyboard shortcut, the clear command, how to scroll back, and how to completely reset the terminal when it gets into a weird state. No prior knowledge is needed—just a terminal window open.

What You’ll Need

  • A Linux system (Ubuntu, Debian, Fedora, Arch, etc.) with a terminal emulator (GNOME Terminal, Konsole, xterm, or similar).
  • Basic familiarity with typing commands in the terminal.

Step-by-Step

  1. Use the keyboard shortcut (fastest). Press Ctrl + L in the terminal. This clears the visible screen, leaving your command prompt at the top. It works in almost every terminal emulator and in the virtual consoles (TTY) as well.
  2. Type the clear command. Type clear and press Enter. This does the same as Ctrl + L but is useful when you want to script it or when the shortcut isn’t working.
  3. Use the reset command for a full reset. If the terminal is showing garbled characters, misaligned text, or if a program has messed up the terminal settings, type reset and press Enter. This reinitializes the terminal and clears the screen completely. It may take a second to respond.
  4. Clear the scrollback buffer too. The clear command and Ctrl + L only clear the visible screen; the scrollback (history) remains. To clear everything, use clear -x (in most terminals) or press Ctrl + Shift + K in GNOME Terminal, or Ctrl + Shift + X in Konsole. Alternatively, you can use printf "\033[2J\033[3J\033[H" to clear the screen, scrollback, and move the cursor home.
  5. Use the terminal’s menu. In most graphical terminals, you can right-click and select “Clear Terminal” or use the Edit menu. This is a convenient mouse-based option.

Common Mistakes

  • Typing cls instead of clear. cls is a Windows command; Linux uses clear.
  • Expecting clear to clear scrollback. By default, it doesn’t. Use clear -x or the terminal’s shortcut.
  • Using reset when you only need to clear. reset can take a moment and may briefly change the terminal settings, which is unnecessary for a simple clear.
  • Forgetting that Ctrl + L works inside many programs. In less, vim, and other full-screen apps, Ctrl + L often refreshes the screen instead of clearing it—which is usually what you want.

Tips

  • Create an alias for a full clear: add alias cls='clear -x' to your ~/.bashrc or ~/.zshrc to have a single command that clears everything.
  • If you want to clear the terminal after every command, you can add clear to your PS1 prompt, but that’s usually annoying—stick to the shortcut.
  • In SSH sessions, Ctrl + L works the same way, so you can clear the remote terminal without any extra setup.
  • To clear the terminal in a script, use clear or tput clear. The latter uses the terminfo database and is more portable across older systems.

Troubleshooting

  • If clear doesn’t work, your terminal may be in a broken state. Try reset. If that fails, close the terminal window and open a new one.
  • If Ctrl + L doesn’t clear, your terminal emulator may have remapped the shortcut. Check the terminal’s keyboard shortcuts in its preferences.
  • If the screen is filled with weird characters, a program may have changed the terminal’s character encoding. Run reset to restore the default.
  • If the terminal is completely unresponsive, press Ctrl + C to interrupt the current process, then try clear or reset. If that doesn’t work, you may need to kill the terminal process from another terminal (e.g., pkill gnome-terminal).

Frequently Asked Questions

What is the difference between clear and reset?

clear only clears the visible screen, leaving the scrollback and terminal settings unchanged. reset reinitializes the terminal entirely, which fixes display glitches but also clears the scrollback and resets settings like line wrapping.

Does Ctrl + L work in all terminals?

Yes, Ctrl + L is a standard control character (form feed) that most terminal emulators interpret as “clear screen.” It works in GNOME Terminal, Konsole, xterm, and even in the Linux virtual consoles.

How do I clear the terminal in a script?

Use the clear command in your script. If you want to clear the scrollback as well, use clear -x (supported in most modern terminals) or send the escape sequence printf "\033[2J\033[3J\033[H".

Why does my terminal show a bunch of numbers and symbols after I run a command?

That usually happens when a program outputs raw escape codes or when the terminal’s character set gets corrupted. Run reset to fix it.

Can I clear the terminal without using the keyboard?

Yes, you can use the terminal’s menu (right-click > Clear Terminal) or type clear and press Enter. Some terminals also have a clear button in the title bar.

Is there a way to clear the terminal after each command automatically?

Yes, you can add clear to your PROMPT_COMMAND variable (in bash) or precmd hook (in zsh), but it’s not recommended because it removes the ability to see previous command output.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →