Copying multiple files to multiple directories

cpxargs

I've a problem copying many files in different directories. Let me explain better:

Let's say I have the following in a dir:

$ ls
file1 file2 file3 file4 file5 dir1 dir2 dir3

and I want to copy every file* in every dir* with a single command. I've tried with:

 echo dir{1..3} | xargs cp file{1..5} '{}' \;

My intent was to tell xargs to process every single dir* from echo and copy all the files in the input processed but this and similar didn't work. I would like to avoid the use of a script because it's a task I have to repeat for about 20 directories and the names of the files are slightly different so I'd prefer modifying a command rather than a script.

Best Answer

echo dir[1-3] | xargs -r -n1 cp file[1-5]

Related Question