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

Viewed 323487

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?

14 Answers

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'

To delete the last output only:

+ L

To clear the terminal completely:

+ K

Command + K will clear previous output.

To clear entered text, first jump left with Command + A and then clear the text to the right of the pointer with Control + K.

Visual examples:

Enter image description here

Do the right thing; do the thing right!

Clear to previous mark: Command + L

Clear to previous bookmark: Option + Command + L

Clear to start: Command + K

Typing the following in the terminal will erase your history (meaning using up arrow will get you nothing), but it will not clear the screen:

history -c
Related