Copy A File To Multiple Sources With tee
Ever wanted to copy a file to multiple sources in the command line all in one command? You can use the linux tee command.
By definition, tee command can read from standard input and write to standard output and files.
The linux command cp
is great to make a straight forward and simple copy, but
tee
can write to several locations at once:
In the above commands, we first make two directories, dir-1 and dir-2 which
are going to be empty. We this use tee
to copy file.txt into both
of those directories. Just a note that tee
also writes to the standard output as
well, so to prevent that you can redirect standard output to /dev/null
like so:
Read more about it here in the man (manual) pages