OSX Shell Clearing Tip

2015-07-26T11:07:47.401194-05:00 2015-08-23T10:10:32.970485-05:00

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

That being said, here is a handy keyboard shortcut that works with both iTerm2 and Terminal.app. 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!