Skip to content
shellmap

clear-hostClear the terminal scrollback — clear / cls equivalent across all 5 shells

Equivalents in every shell

Bashunix
clear

External tool (`/usr/bin/clear`) from `ncurses-bin`. Sends the terminal-specific clear sequence read from `terminfo`. The keyboard shortcut `Ctrl+L` does the same thing without forking. For a hard reset (including weird terminal state), `reset` is the heavier hammer.

Zshunix
clear

Same external `clear`. Zsh adds `clear-screen` as a ZLE widget bound to `Ctrl+L` by default — same effect, faster (no fork). To remap to another key: `bindkey "^X" clear-screen`.

Fishunix
clear

Same external `clear`. Fish binds `Ctrl+L` to the `clear-screen` function by default; `bind \ck clear-screen` to also map `Ctrl+K`. `clear` in fish 3.4+ is an alias for the external binary.

PowerShellwindows
Clear-Host

Aliased as `cls`, `clear`. Implemented as a function (not a cmdlet) that calls `$Host.UI.RawUI.Clear()` if available, otherwise falls back to a sequence of `Write-Host` newlines. Visible behaviour matches `clear` / `cls` on every terminal.

cmd.exewindows
cls

Built-in. Clears the visible buffer; on Windows Terminal it also resets the scrollback (older Win10 conhost preserves the scrollback off-screen). No options. The PowerShell `cls` alias works in pwsh, not in cmd — they happen to share the name.

Worked examples

Clear the screen interactively

Bash
clear
Fish
clear
PowerShell
Clear-Host
cmd.exe
cls

Clear inside a script

Bash
printf "\033[H\033[2J"
PowerShell
[Console]::Clear()

Bind a custom hotkey to clear

Zsh
bindkey "^X" clear-screen
PowerShell
Set-PSReadLineKeyHandler -Chord Ctrl+x -Function ClearScreen

Gotchas

  • `Clear-Host` is a FUNCTION, not a cmdlet — you can `Get-Content Function:Clear-Host` to see the body. On terminals that don't support the necessary RawUI methods (some redirected or null hosts), it silently does nothing instead of erroring.
  • Clearing does NOT wipe the scrollback by default — historical content is just scrolled above the visible top. To also clear the scrollback in pwsh, use `[Console]::Clear()` (calls .NET directly) or send the ANSI sequence `Write-Host "`e[3J"` (`ESC[3J`). Windows Terminal honours `e[3J`; older conhost ignores it.
  • Inside `Invoke-Command` or remote sessions, `Clear-Host` clears the LOCAL host's view, not the remote — it has no remote effect. Use `Invoke-Command -ScriptBlock { Clear-Host }` to clear on the remote side, but this is rarely useful because remote output is collected and displayed all-at-once locally.
  • `cls` is a pwsh ALIAS pointing to `Clear-Host` — it does NOT invoke the cmd-builtin `cls.exe` (no such binary exists). The cmd `cls` only works inside cmd.exe. Cross-shell muscle memory works because the aliases align, not because the underlying mechanism is the same.
  • `clear` and `cls` aliases are present on every pwsh platform — but on Linux/macOS pwsh, `& clear` (forced external resolution) reaches `/usr/bin/clear` which uses terminfo for terminal-specific sequences. The cmdlet form via `$Host.UI` is usually fine; the external form is safer if you're running inside an emulator with non-standard escape handling.

WSL & PowerShell Core notes

pwsh`Clear-Host` and its `cls` / `clear` aliases work on every pwsh platform. The implementation differs slightly under the hood — on Windows it uses `$Host.UI.RawUI.Clear()`, on Linux/macOS it may fall back to writing the ANSI clear sequence. Both produce the same visible effect in any ANSI-aware terminal (Windows Terminal, iTerm2, GNOME Terminal). For scrollback-clearing behaviour, the platform-native `clear -x` (POSIX) or `[Console]::Clear()` are more reliable than the alias.
WSLInside WSL, `clear` is the standard ncurses tool and works identically to native Linux — the WSL terminal emulator (Windows Terminal or alternatives) handles the escape sequences. From Windows-side pwsh inside a WSL UNC path, `Clear-Host` clears the local Windows Terminal pane, not anything WSL-specific. Both sides share the visible terminal buffer so the effect is unified.

Related commands