Skip to content

tee

See command output and log at the same time

date | tee -a mylog.og

Remember to use the -a flag here to append to file. So the usage presented here is a simple:

tee -a someFile

tee with process substitution

process substitution

It's called "process substitution" because you're substituting a process (and its output) in place of where you'd normally put a filename.

My goal here was to copy the date to the clipboard while also creating the filename with it.

nvim "thought-dump-$(date '+%Y-%m-%d-%H-%M' | tr -d '\n' | tee >(wl-copy)).md"

Using tee, I can still get the output to stdout while being able to write to a file at the same time. I can leverage this behavior of tee with >(wl-copy). With this I'm still writing to a file (a named pipe to be more accurate eg: /dev/fd/63 ), to which the wl-copy would be listening like wl-copy < /dev/fd/63).

From the perspective of tee, and your own when using it, tee is writing to a file.

tee just passing the stdout along while also saving to a file

maim -s | tee ~/Pictures/$(date '+%s').png | xclip -i -selection clipboard -target image/png

Comments