This question is a sequel of sorts to my earlier question, Creating numerous directories using mkdir.I am using the bash shell.  I have created fifty directories, each starting with the prefix s, using the command:mkdir $(printf s%02i  $(seq 1 50))which pads to the second digit with zeros.  That is, the directories that I obtain are of the form s01, s02, ..., s49, s50.Now I would like to use cp to copy a single file (for example, test.txt) to each of the fifty directories.  Is it possible to do this in a way analogous to that above?  For example, would the following work? I am relatively new to Unix/Linux, so I don't really want to try this until someone please gives me an indication that it is safe. cp test.txt $(printf s%02i.txt  $(seq 1 50))Looking at the man page for cp, it does not look like cp supports multiple destinations like this, however:NAME       cp - copy files and directoriesSYNOPSIS       cp [OPTION]... [-T] SOURCE DEST       cp [OPTION]... SOURCE... DIRECTORY       cp [OPTION]... -t DIRECTORY SOURCE...DESCRIPTION       Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.       Mandatory  arguments  to  long  options are mandatory for short options       too.
Copying a single file to multiple directories using cp
bash;shell;cp
If you wanted to use the output from your command to copy the file to each directory using cp, you could always pipe it to xargs:printf s%02i  $(seq 1 50) | xargs -n 1 cp test.txtThere shouldn't be any concerns about the safety of parsing the output since you know its format and content before hand--the risk of encountering meta characters and space in file names isn't really an issue here.Alternatively, assuming the directories already exist, you could try something like:find . -maxdepth 1 -type d -name 's[0-9][0-9]' -print0 | xargs -0 -I {} cp test.txt {}or with no pipe:find . -maxdepth 1 -type d -name 's[0-9][0-9]' -exec cp test.txt {} \;The last two commands will find any files in the current directory and cp test.txt to them. The -maxdepth 1 option will avoid any sub directories receiving the file as well. Be warned that 's[0-9][0-9]' is matching against s followed by any two digits, which means if for some reason you have s99 in the cwd, it will also receive a copy of test.txt.