Use case: I'm working in bash/terminal and have been typing several commands and I've just run something and it's spewed some output. I'm trying to find where that output started and have to visually search the page to see where the command is that I typed.

Now had I anticipated that I was going to struggle to find the start of the content I would have run clear && <my command>.

So what I'm looking for is something like clear -1 which would (1) grab all the content since the last command, (2) run clear, and then (3) paste the content into the terminal.

  • 4
    Have you considered using <my command> | less ? – John1024 Apr 9 '15 at 1:05
  • 1
    That would work but replies on anticipating that I would need it. clear && <my command> works (or quicker CTRL + L as @SabinReneFigaro pointed out) just as well but again requires that you know ahead of time. I'm looking for something that will work after the fact. – Guy Apr 10 '15 at 17:15
  • 1
    bash's precognition is worse then yours... Any solution that I can think of that adds precognition to bash would be ugly. e.g. you could spawn a new terminal for each and every command you type and then have to close it after the command finishes... – Fabby Apr 12 '15 at 10:28
  • 1
    @Fabby I don't think so. If bash stored the results of the last command in a buffer then it could easily (1) clear and (2) paste. – Guy Apr 12 '15 at 17:36

As mentioned piping the command to | less, will make it clear.

If you are using bash you can also press CTRL +L to clear, then run the command. This is what i do :)

  • Thanks - both of those work but rely on precognition that you need them and can't be used after the fact. – Guy Apr 10 '15 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.