LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   find and copy files into multiple directories (http://www.linuxquestions.org/questions/linux-newbie-8/find-and-copy-files-into-multiple-directories-164968/)

avargas22 04-01-2004 10:02 AM

find and copy files into multiple directories
 
I have a client who wants me to write a script that finds php files and then duplicates them in their current directory. I want to input a starting directory and have this script descend into the directory hierarchy and update all of the php files.

This is what I figured out so far, thanks to this board:
find <start_directory> -iname "*.php" -exec cp {} <new_dir> \;

However, if i replace <new_dir> with a "." it places all of the duplicates in one directory.

I would like to copy the files to their current directory. I guess what i need is some kind of variable which represents the path location of the current file that is being found.

I searched the man pages and found %h, but i do not know how to use it in the find command for my purpose

i was thinking something like this, but it is not right:
find /www/ -iname "*.php" -exec cp {} %h%p \;

If anyone has a solution, I would very much appreciate your help.

Thanks,
Anthony

fzzy 04-01-2004 10:52 AM

try
find <start_directory> -iname "*.php" -exec cp {} {}.dup \;

or use dirname to get the folder of {}

avargas22 04-01-2004 11:11 AM

that works great... however, the reason the client wants this to be done is to update the creation or modification date of the files for another script she has running.

By putting .dup, it does not copy over the original file. I took out the ".dup" and it wont do the copy because it says the two files are the same. is there a way to override this effect, or some other method of updating the creation or modification date of the file?

Thanks again for your help fzzy.

anthony


All times are GMT -5. The time now is 05:13 AM.