I find remembering to pipe the output of my commands into a specific file to be a bit annoying, my solution is a function in my .bash_profile
that catches the output in a file and returns the result when you need it.
The advantage with this one is that you don't have to rerun the whole command (when using find
or other long-running commands that can be critical)
Simple enough, paste this in your .bash_profile
:
# catch stdin, pipe it to stdout and save to a file
catch () { cat - | tee /tmp/catch.out}
# print whatever output was saved to a file
res () { cat /tmp/catch.out }
$ find . -name 'filename' | catch
/path/to/filename
$ res
/path/to/filename
At this point, I tend to just add | catch
to the end of all of my commands, because there's no cost to doing it and it saves me having to rerun commands that take a long time to finish.
Also, if you want to open the file output in a text editor you can do this:
# vim or whatever your favorite text editor is
$ vim <(res)