Skip to content

Instantly share code, notes, and snippets.

@informatimago
Created September 10, 2018 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save informatimago/2f0a434e47f3e983e802092c505e3789 to your computer and use it in GitHub Desktop.
Save informatimago/2f0a434e47f3e983e802092c505e3789 to your computer and use it in GitHub Desktop.
Here is a nice feature; you could patch bash to do it:
every time you run a command, bash would redirect the
output automatically behind the scene. By default it
would tee it to the tty as always, but while the command
is running (and even after, from the history), we could
redirect the output to a file or a pipe, dynamically.
And conversely, when we run a pipe, we could at any time
have a look at the data going thru a pipe. For example
you would type:
find / -type f | wc -l
then at any time during the execution of this pipeline,
you could select the pipe, and insert there a tee as if
you had typed:
find / -type f | tee -a /dev/tty | wc -l
then at any time (during the execution, or later), you
could select the last command and redirect its output
to a file out.txt, as if you had typed:
find / -type f | wc -l > out.txt
(notice that it means that the shell would have taken
a copy of the data written to the terminal, so that it
could copy it to the file before redirecting the output
(or if we do that after wc exited). And so on. For
example, you could start typing:
find / -type f
and get a lot of output, then you could redirect it on
the fly, as if you had typed:
find / -type f | wc -l
(with the lines already output to the terminal being
redirected or not (on option) to wc -l.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment