Today I Learned

hashrocket A Hashrocket project

How to clear a Mac terminal and its scroll-back?

Just type this: clear && printf '\e[3J'

Or even better create an alias for that, here's mine:

alias clear='clear && printf "\e[3J"';

Here's what I've learned today:

On Mac a regular clear is pretty much the same as typing Control + L on iTerm2. This clears the screen what's good but sometimes I want to clear all the scroll-back to clean the noise and find things faster.

In order to clean the scroll-back I was performing a Command + K. This cleans the screen and the scroll-back. That's great, except that it messes up with tmux rendering and tmux holds all the scroll-back per pane, so it won't work at all.

So my new alias solves that as after clear the screen it also sends a terminal command to reset the scroll back through printf '\e[3J' and this keeps tmux working just fine!

See More #command-line TILs