LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-01-2004, 10:02 AM   #1
avargas22
LQ Newbie
 
Registered: Apr 2004
Posts: 2

Rep: Reputation: 0
Exclamation 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
 
Old 04-01-2004, 10:52 AM   #2
fzzy
Member
 
Registered: May 2003
Posts: 31

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

or use dirname to get the folder of {}

Last edited by fzzy; 04-01-2004 at 10:54 AM.
 
Old 04-01-2004, 11:11 AM   #3
avargas22
LQ Newbie
 
Registered: Apr 2004
Posts: 2

Original Poster
Rep: Reputation: 0
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy files from multiple directories into one directory MadRabbit Linux - Newbie 8 02-07-2014 07:56 PM
Find excluding multiple directories with a wildcard pteigeler Linux - Software 1 09-02-2005 10:57 AM
Copy files from different directories fiomba Linux - Software 3 02-11-2005 03:01 AM
Copy one file to multiple directories cmfarley19 Linux - General 9 11-10-2004 12:57 PM
Help I need help tarring multiple files in multiple directories VisionZ Linux - Newbie 28 03-25-2004 05:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration