Clear terminal scrollback on mac

Created: — modified: — tags: mac

TL;DR: printf 'e[3J'

Depending on your terminal, simple clear might clean only the visible portion of the screen, leaving scrollback intact. Sometimes it might be not what you want, and then printf '\e[3J' might help you. Note that sometimes this command might clean only scrollback, and you might want to have both!

Source: stackoverflow.

A good header for a script that produces a lot of output then looks like this:

clear
printf '\e[3J'
set -ex

It first clears visible screen and scrollback, and then enables failing on error and echoing lines to be executed