How can I clear previous output in Terminal in Mac OS X?

eonil picture eonil · Feb 4, 2010 · Viewed 261.2k times · Source

I know the clear command that 'clears' the current screen, but it does this just by printing lots of newlines - the cleared contents just get scrolled up.

Is there a way to completely wipe all previous output from the terminal so that I can't reach it even by scrolling up?

Answer

Alok Singhal picture Alok Singhal · Feb 4, 2010

To clear the terminal manually:

+K

Command+K for newer keyboards

To clear the terminal from within a shell script;

/usr/bin/osascript -e 'tell application "System Events" to tell process "Terminal" to keystroke "k" using command down'