Forum Moderators: bakedjake

Message Too Old, No Replies

recursive copying of files into subdirectories

how do we recursively copy files into subdirectories

         

Veaglarwen

10:35 am on May 4, 2003 (gmt 0)



The site owner of a site I help out with has run into an issue that she is sure she's solved before, but cannot figure out now. She's using Unix now and on her website she uses an .htaccess file to eliminate hotlinking of images. She wants to include this .htaccess file in all subdirectories in a particular directory. Now, the command we thought should have worked was...

cp -r .htaccess directory

but this is only copying it in the first subfolder. Is there ANY function that would get this file copies in all subdirectories with just one call?

douglay

2:12 pm on May 4, 2003 (gmt 0)

10+ Year Member



This should work:

for i in `find <directory> -type d`; do cp .htaccess $i; done

Be sure to use the backtick, not regular quotes, to surround the find command. The backtick operator is used in the bash shell to execute a "command-within-a-command."