To copy a file to multiple directories in Linux, you can use the `cp`
command with the `xargs`
command. Here all the destination directories will be piped as standard input to the `xargs`
command. and specify a list of directories separated by space. For example:
echo dir1 dir2 dir3 | xargs -n 1 cp -v file.txt
This will copy the file file.txt
to the directories dir1, dir2, and dir3.
Alternatively, you can use the for loop to copy the file to multiple directories. For example:
for dir in dir1 dir2 dir3; do
cp file.txt $dir
done
This will loop through the list of directories and copy the file to each of them.
You can also use the find command to copy the file to multiple directories. For example:
find dir1 dir2 dir3 -type d -exec cp file.txt {} \;
This will find all directories named dir1, dir2, and dir3 and copy the file to each of them.
Note: Make sure you have the necessary permissions to copy the file to the target directories.