To clear the entire terminal screen in Linux, macOS, or Windows (including WSL), use the command clear—it formats the entire terminal window like a fresh start. For more control (like removing hidden commands or resetting scrollback), use cmd + L (macOS/Linux) or type Ctrl + K (common across systems). If these don’t work, terminal emulators like iTerm2 (macOS) or Alacritty (cross-platform) support powerful reset commands.

What You'll Need

  • A terminal emulator installed (built-in on Linux/macOS, or apps like Windows Terminal, iTerm2, or VS Code integrated terminal).
  • Basic command-line familiarity (though no prior knowledge is needed).
  • Admin/root privileges only required for advanced scrollback removal (see Tips section).

Step-by-Step

  1. Basic Clear (most terminals): Type clear and press Enter. This erases the entire screen and starts a new prompt at the top-left corner. Works in all Unix-like terminals (Linux, macOS) and Windows Terminal with Linux subsystem (WSL).
  2. Alternative: Clear to Top (macOS/iTerm2 shortcut): Press ⌘ + L (Command + L) on macOS or Linux. This removes everything below the current cursor position without affecting the scrollback buffer. Note: This doesn’t work in Windows Terminal unless configured via preferences.
  3. Force Reset (Linux only): In terminal emulators like GNOME Terminal, Konsole, or Alacritty, type: printf '\033[H\033[2J' and press Enter. This sends ANSI escape codes to move the cursor to the home position (top-left) and clear the screen. Works in most Linux terminals, including WSL. The codes are ANSI-standard; some older terminals may ignore them.
  4. Remove Scrollback Buffer (advanced): Open your terminal’s settings (e.g., Preferences > Profiles > Text in iTerm2) and look for:
    1. Scrollback size (set to 0 to disable history persistence).
    2. Clear on startup (enable to reload terminal completely).
    Warning: Disabling scrollback may lose recent commands permanently.
  5. Windows Terminal Workaround: If clear doesn’t work in Windows Terminal, try:
    1. Open the integrated terminal in VS Code (File > New Terminal).
    2. Type cls (Windows) or clear (WSL).
    Note: Windows Terminal defaults to cls for native Windows; WSL uses clear.

Common Mistakes

  • Using Ctrl + C or Ctrl + D: These interrupt commands or exit the shell, not clear the screen. Use clear instead.
  • Typing reset: This resets terminal attributes (foreground/background colors) but leaves the screen unchanged. Combine it with clear for a full reset: reset; clear
  • Ignoring terminal emulator quirks: Some emulators (e.g., PuTTY) use different escape sequences. Check their documentation for clear equivalents.
  • Overlooking hidden shells: If you’re in a subshell (e.g., bash -i), clearing won’t affect the parent shell. Run exit or return first.

Tips

  • Permanent Workaround: Add this to your shell config file (~/.bashrc, ~/.zshrc, or ~/.profile): function clear { clear; fi } Then type clear forever. MacOS/Linux shortcuts won’t conflict.
  • macOS/iTerm2 Pro Tip: Enable Clear on startup in preferences to avoid manual clearing after every session.
  • Scrollback Recovery: If you lose commands, check your shell’s history file (e.g., ~/.bash_history) and reload it: history; source ~/.bash_history
  • Color Reset: To clear colors *and* the screen (e.g., after a long script), use: printf '\033[2J\033[3J' \033[3J clears color attributes.
  • Admin Privileges: To empty the scrollback buffer system-wide (Linux only), run: sudo mv ~/.bash_history ~/.bash_history.bak Then recreate the file. Warning: This deletes all terminal history.

Troubleshooting

  • If clear fails:
    1. Check if your terminal emulator supports it (e.g., cat /dev/tty lists the current terminal type).
    2. Try echo -e "\e[H\e[J" (ANSI escape codes) as a fallback.
    3. For Windows Terminal, ensure the clear option is enabled in settings: Settings > Profiles > Text > Clear on startup.
  • If the screen stays blank after clearing:
    1. Check for terminal mode conflicts (e.g., non-standard terminal modes).
    2. Restart the terminal emulator or reboot the system.
  • If you need to clear *both* the screen *and* the command history:
    1. Type history -c to clear the shell history.
    2. Then use clear or ANSI escape codes.

Frequently Asked Questions

Can I clear the terminal without losing my current command?

Yes. If the cursor is at the start of a line, ⌘ + L (macOS) or Ctrl + L (Linux) clears only what’s below it. Otherwise, use clear to reset the entire screen.

How do I clear a terminal in Windows PowerShell?

PowerShell uses cls like CMD, but it doesn’t support clear. Use: Clear-Host (PowerShell built-in) or Set-Content -Path $null -Value '' (force-clear).

Why does clear not work in some terminals?

Some terminals (e.g., old DOS boxes or web terminals) ignore clear. Try printf '\033[2J' (ANSI escape) or check your terminal’s manual for vendor-specific commands.

How can I automatically clear the terminal on startup?

Add this to your shell config file: clear (for bash/zsh) or printf '\033[H\033[2J' (for ANSI-compliant terminals).

What if I accidentally cleared my shell history?

Restore it with history -r ~/.bash_history (Linux/macOS). For permanent clearing, back up the file first: cp ~/.bash_history ~/.bash_history.bak

Does clearing the terminal affect other apps?

No, clearing the terminal only affects the current shell/emulator window. Other apps (e.g., browsers, IDEs) remain unaffected.