Is it possible to copy a single file to multiple directories using the cp command ?
I tried the following , which did not work:
cp file1 /foo/ /bar/
cp file1 {/foo/,/bar}
I know it's possible using a for loop, or find. But is it possible using the gnu cp command?
Suppose you want to copy
fileName.txt
to all sub-directories within present working directory.Get all sub-directories names through
ls
and save them to some temporary file say,allFolders.txt
Print the list and pass it to command
xargs
.Wildcards also work with Roberts code
For example if you are in the parent directory of you destination folders you can do:
for i in $(ls); do cp sourcefile $i; done