OSX Shell Clearing Tip

First off you’re serious about your shell and using Mac OSX for development you should really be using iTerm2instead of the built in default Terminal app.

That being said, here is a handy keyboard shortcut that works with both iTerm2 and I often find myself running something like:

$ find ./ | grep tests

Which returns a ton more results than I intended. Which leads to piping the results to another grep or two to quickly find what I’m looking for in a file tree. But if you immediately run another shell command both of the results are in your scroll buffer which isn’t exactly optimal all of the time.

Hitting Cmd+k will clear the shell buffer (aka scroll buffer) without clearing out your history or the current text at your shell prompt. “k for clear” is how I remember it. So you can for example hit up arrow and add

| grep -v '.pyc'

to the previous shell command and THEN hit Cmd+k and it will clear your scroll buffer without clearing the edits to your command.

This way your scroll buffer only contains the output of the immediately preceding command and nothing else. Hope this helps!

Posted 10 April 2014