- In computing, tee is a command in command-line interpreters (shells) using standard streams which reads standard input and writes it to both standard output and one or more files, effectively duplicating its input. It is primarily used in conjunction with pipes and filters. The command is named after the T-splitter used in plumbing.
is part of the package.
To write content to files:
$ input stream | tee file1 file2...
By default, tee overwrites content in files when used again. However, if you want, you can append content in files by using the
For more usage, see.
Tips and tricks
Write to protected files
tee is very useful for writing to protected files:
$ input stream | sudo tee --option protected file1 protected file2...
when a simple
>> would not have worked because of permissions.
:w !sudo tee %
You can add this to your
~/.vimrc to make this trick easy-to-use with
:w!! mapping in command mode:
" Allow saving of files as sudo when I forgot to start vim using sudo cmap w!! w !sudo tee > /dev/null %
> /dev/null part explicitly throws away the standard output since we don't need to pass anything to another piped command. More detailed explanation of how and why this works can be found in How does the vim “write with sudo” trick work? article on StackOverflow.