Copying file to multiple locations

Im sure this should be easy but it is defeating me right now

I need to copy a couple of files to all sudirectories within a certain directory. There are hundeds of sub directories so cannot simply copy/move files. The files need to be in every directory.

Similar to needing an .ico file in every directory of a website to get the favicon to work.

Im guessing its just a simple unix script I need  :-S

TIA
bluerabbitAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tim_UtschigCommented:
cd /certain/directory
find . -maxdepth 1 -mindepth 1 -type d -print | xargs -l cp file1 file2
Tim_UtschigCommented:
-mindepth/-maxdepth doesn't work on Solaris...

cd /certain/directory
for D in *; do [ -d "$D" ] && cp file1 file2 "$D/"; done

(assumes bourne shell, no dirs starting with dots, and not too many dirs to overload the arg list)
amit_gCommented:
find . -type d | grep -v '^\.$' | sed 's/^/cp FileName.ico /' | sh
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Tim_UtschigCommented:
This solves all the problems with the example from my previous comment, but is slower:

cd /certain/directory
ls -a | xargs -i sh -c '[ -d "$0" ] && [ "$0" != "." ] && [ "$0" != ".." ] && echo cp file1 file2 "$0/"' {}
Tim_UtschigCommented:
Oops, forgot to remove the "echo" I was using for testing.
Tim_UtschigCommented:
Shortened (and maybe sped) up a little:

cd /certain/directory
ls -a | xargs -i sh -c '[ -d "$0" -a "$0" != "." -a "$0" != ".." ] && cp file1 file2 "$0/"' {}
ahoffmannCommented:
> I need to copy a couple of files to all sudirectories within a certain directory.

cd /path/to/certain/directory
(ls patter-for-files;echo NOMOREFILES;ls -F )|awk '/NOMOREFILES/{f=1;next;}(f!=1){d[i++]=$0}/\/$/{for(x in d) {print "cp "d[x]" "$0}}'

If this is what you want, then simply pipe the result to sh
(should work on any *nix in any shell)
bluerabbitAuthor Commented:
Thanks.

Have tried

cd /certain/directory
ls -a | xargs -i sh -c '[ -d "$0" -a "$0" != "." -a "$0" != ".." ] && cp file1 file2 "$0/"' {}

and

(ls patter-for-files;echo NOMOREFILES;ls -F )|awk '/NOMOREFILES/{f=1;next;}(f!=1){d[i++]=$0}/\/$/{for(x in d) {print "cp "d[x]" "$0}}'

Both copy the files to all the directories within the cwd but not to all the sub diectories within those and sub dirs within those etc.

Thanks
ahoffmannCommented:
> .. copy the files to all the directories within the cwd but not to all the sub diectories within those
and in your question:
> I need to copy a couple of files to all sudirectories ..

So you see that you have to specify clearly what you want (which is done now;-)

cd /certain/directory
(ls patter-for-files;echo NOMOREFILES;find . -type d -print)|awk '/NOMOREFILES/{f=1;next;}(f!=1){d[i++]=$0}/\/$/{for(x in d) {print "cp "d[x]" "$0"/"}}'

it's a one-liner, but I guess that it is not very usefull in a lot of cases ...
amit_gCommented:
What was wrong with

find . -type d | grep -v '^\.$' | sed 's/^/cp FileName.ico /' | sh

?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tim_UtschigCommented:
> Both copy the files to all the directories within the cwd but not to all the sub diectories within those and sub dirs within those etc.

Add options such as -rp to the cp command, e.g:

cd /certain/directory
ls -a | xargs -i sh -c '[ -d "$0" -a "$0" != "." -a "$0" != ".." ] && cp -rp file1 dir1 file2 dir2 "$0/"' {}
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.