Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to partially clear my terminal scrollback history, but only from where I have selected with my mouse in the scrollback and up. Is this possible? I'm on a Mac, and I use iTerm2 and Terminal.

share|improve this question
bash doesn't have any notion of scrollback; that's something your terminal emulator manages. – chepner Apr 1 '13 at 18:03
@chepner - ok, good point. I just reframed the question to not be about bash. – Javid Jamae Apr 1 '13 at 18:56
up vote 17 down vote accepted

Not sure about partially, but you can fully clear your scrollback with Cmd+K. Control+L will only clear the screen, not the scrollback content/history/buffer.

If you want the partial scrollback badly enough, this would probably be the place to implement it.

share|improve this answer
Thanks, but man, that is some nasty code! I don't think I'd ever want anything so badly that I would have to get in to that codebase. :-) – Javid Jamae Dec 16 '13 at 23:00

If others got here searching for an escape sequence like command-K in iTerm 2, you can use

printf '\e]50;ClearScrollback\a'

printf '\ec' and clear;printf '\e[3J' work in Terminal but not in iTerm 2.

share|improve this answer
What does this have to do with partially clearing scrollback? – Javid Jamae Mar 10 '14 at 18:41
This question was one of the top Google results for iterm clear scrollback. – user495470 Mar 11 '14 at 12:23
this will make the text flash if you immediately print what you just cleared. but it works! – Andrew Anthony Gerst Apr 12 at 13:39

This is not possible, but you can clear just the screen by pressing Control+L.

share|improve this answer

This will clear the history completely. history -c

No way I could find to do a partial.

share|improve this answer

If I have correctly understood your question, I think that you can achieve that by manually editing your history file, ~/.bash_history.

P.S.: In order to save your current session, you have to first close the Terminal.

share|improve this answer
No, I think you misunderstood. The .bash_history file is for the command history, not the terminal scrollback history. – Javid Jamae Dec 16 '13 at 22:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .