5 Ways to Clear Your Mac Terminal Screen and Scrollback

Updated

clear terminal mac

To clear the Terminal screen on a Mac, type clear and press Return, or press Control-L. Terminal’s Edit menu has three more: Clear to Start (Command-K), Clear Scrollback (Option-Command-K) and Clear Screen (Control-Command-L).

Five ways to clear the Terminal screen and scrollback on a Mac

The five ways come from three places: a command, your shell and Terminal’s Edit menu. This is what each one’s documentation or menu says, for Terminal 2.15 on macOS Tahoe 26.6:

Way Comes from What the docs or the menu say
clear, then Return The clear command The macOS manual says it clears your screen, “including its scrollback buffer (if the extended ‘E3’ capability is defined)”
Control-L Your shell The zsh manual describes its clear-screen widget as “Clear the screen and redraw the prompt”
Command-K Terminal: Edit > Clear to Start Apple’s guide lists it as “Clear to start”
Option-Command-K Terminal: Edit > Clear Scrollback Not in Apple’s shortcut list; the menu item is called Clear Scrollback
Control-Command-L Terminal: Edit > Clear Screen Not in Apple’s shortcut list; Apple’s guide says to clear the window by choosing Edit > Clear Screen

Apple’s guide doesn’t spell out what the three Edit menu commands leave in the scrollback. To see it on your Mac, run seq 1 200, try one, then scroll up.

Control-L comes from your shell, not from Terminal. In zsh it runs the clear-screen widget, and bash has the same binding. The other three shortcuts are Terminal’s own Edit menu items. Command-L and Option-Command-L are something else: Clear to Previous Mark and Clear to Previous Bookmark, which Apple lists with the mark and bookmark shortcuts.

The macOS manual says clear also clears the scrollback buffer if your terminal type defines the E3 capability, which xterm-256color does (run echo $TERM to see yours). It does that by sending the code ESC [ 3 J before it clears the screen; printf '\033[3J' sends only that code.

The ncurses manual says newer versions of clear accept -x to skip the scrollback, but Apple’s clear ignores options, so clear -x behaves exactly like plain clear. To clear the screen from the command line without sending that scrollback code, use tput clear.

I read the menu names and shortcuts from Terminal 2.15 on macOS Tahoe 26.6. Apple’s Terminal User Guide agrees where it covers them: it lists Command-K as Clear to Start and tells you to choose Edit > Clear Screen to clear the window. Its shortcut list is the same for macOS 27 Golden Gate, Tahoe 26 and Sequoia 15, and it does not include Option-Command-K or Control-Command-L, so look in the Edit menu for those.

To keep less scrollback in the first place, choose Terminal > Settings > Profiles, select your profile, click Window, and under Scrollback turn on Limit number of rows to and enter a number.

Fix a garbled Terminal window with reset

If a program crashes and leaves Terminal showing odd characters, or not echoing what you type, run reset. The macOS manual says it puts the input modes back to normal (echo on, ordinary line input) and then initializes the terminal, and that it is useful “after a program dies leaving a terminal in an abnormal state”. If Return no longer works, press Control-J, type reset, and press Control-J again; the manual warns that Return may stop working and that the command may not be echoed.

Terminal also has Shell > Reset (Option-Command-R) and Shell > Hard Reset (Control-Option-Command-R), which Apple’s guide calls soft and hard resets of the terminal emulator state. Two shorter commands only print reset sequences:

tput reset         # print the terminal's reset sequences
printf '\033c'     # print just the first one, ESC c

Use reset itself when typing is broken, because it is the one the manual says restores echo and normal line input.

Clear the screen in iTerm2

iTerm2 uses different names. Its documentation says Edit > Clear Buffer “clears the entire terminal history and the mutable area”, while Edit > Clear Scrollback Buffer “clears scrollback history, preserving the mutable area”. The documentation lists no default shortcuts for them, so open the Edit menu to see yours.

Clear your zsh history on a Mac (~/.zsh_history)

Clearing the screen does not touch your command history. On a Mac, zsh (the default shell for new accounts since macOS Catalina) saves it by default in ~/.zsh_history. history -c is a bash command; zsh answers bad option: -c.

Terminal keeps a second copy. Its setup script, /etc/zshrc_Apple_Terminal, gives each window its own history file in ~/.zsh_sessions and loads it again when the window is restored. Deleting ~/.zsh_history alone therefore leaves your commands behind, and the window you are typing in saves its commands again when it closes. Close your other Terminal windows first. If privacy is the point, note that everything you typed also sits in the window’s scrollback, which these commands don’t touch; the Edit menu item called Clear Scrollback (Option-Command-K) is the one to try. Then run this in the last window:

rm -f ~/.zsh_history
rm -f ~/.zsh_sessions/*.history*
unset HISTFILE
exit

The unset HISTFILE line matters: the zsh manual says that if HISTFILE is unset, the history is not saved. If zsh answers “no matches found” to the second line, there were no per-window files, which is fine. There is no undo, so copy ~/.zsh_history somewhere first if you might want it back, and avoid a wildcard such as ~/.zsh*, which also matches ~/.zshrc, your shell settings.

To keep a command out of the history from the start, add setopt HIST_IGNORE_SPACE to ~/.zshrc and put a space before the command.

Photo of author
Sudhir P. founded HeatWare.com in 1999 and has built and operated it full-stack ever since; it is now used by more than 88,000 people. He writes here about the PostgreSQL, MySQL, Linux and DevOps work that keeps it running. Articles are rewritten only after the commands in them have actually been run, and the verification scripts are published alongside them so anyone can check the claims. Reach him at blog@heatware.net.