Possible Duplicate:
How do I reuse the last output from the command line?

If I for example type

aptitude search dia

I get a lot of unrelated stuff. At that point, I suspect that | head or | grep -w dia would have streamlined the result (had I thought of that). I could type !! | head or !! | grep -w dia but then the search is performed anew. But that's unnecessary; I'm already happy with that part. So, is there anyway to do like, most_recent_stdout | whatever.

(Note that this is just an example so I'm not looking for aptitude options or anything like that.)


1 Answer 1


To make this work, you would need to redirect stdout to a file and then cat that file. Bash doesn't save the output of commands on its own.

Alternatively, you could use a program like screen that allows you to save a transcript of your session to a file. You would get the output of everything and the command lines though.

  • If redirecting to a file could somehow be automatic, a small tool to access those files wouldn't be that difficult to write. But If you had to write > stdoutlog after each command, it wouldn't be worth the effort because you would never use it anyway. May 22, 2012 at 18:36
  • 2
    You could certainly implement this by hacking bash, but I would strongly advise against it. For a start, it would litter your filesystem with these files, potentially overwriting other files. Furthermore, you would have trouble redirecting output to another file. May 22, 2012 at 18:45

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