I have tried to copy a file test.txt
to multiple directories with one command:
cp ~/test.txt ~/folder1 ~/folder2
But I didn't succeed. Is there a way to do that in one command so I can copy a file or even a folder to multiple directories?
command linecp
I have tried to copy a file test.txt
to multiple directories with one command:
cp ~/test.txt ~/folder1 ~/folder2
But I didn't succeed. Is there a way to do that in one command so I can copy a file or even a folder to multiple directories?
Best Answer
cp
can copy from multiple sources, but can't copy to multiple destinations. Seeman cp
for more info.The only bash command that I know which can copy/save to multiple destinations is
tee
.You can use it in your case as follows:
Note that
tee
also writes the input to the standard output (stdout). So if you don't want this, you can prevent it by redirecting standard output to/dev/null
as follow: