Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-19-2007
Registered User
 
Join Date: Jun 2005
Location: Middletown, PA
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Trying to Copy Files Changed Recently

I have been toying around with a script that will copy all files altered in a development directory over to a testing directory and have been trying to construct the command to meet my needs.

Basically I am using find in a directory to see what files have changed over the past 24 hours. Then if I find any files that have changed I want to copy it over to another directory maintaining permissions. I have been toying with both these commands.

cd /home/common-dev
find . -mtime -1 |xargs cp -p {} ../common

I am getting errors about files not being directories so i must have something off with my cp command or how I am understanding how xargs is passing the filename.

cd /home/common-dev
find . -mtime -1 | cpio -opmvd ../common

The cpio command is not retaining permissions but it is doing the copies great.

Any suggestions or enlightenment would be appreciated. Thanks in advance.
Sponsored Links
    #2  
Old 01-19-2007
...@...
 
Join Date: Feb 2004
Location: NM
Posts: 9,656
Thanks: 164
Thanked 645 Times in 622 Posts
Do you want to copy directories - it is not needed if they already exist....

Code:
find . -mtime -1 -type f |\
while read file 
do
     cp -p $file ../common
done

Sponsored Links
    #3  
Old 01-19-2007
Registered User
 
Join Date: Jun 2005
Location: Middletown, PA
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you

Thank you, I ended up doing something like this.


Quote:
find . -mtime -1 -type f |\
while read file
do
cp -rp $file ../${AREA}/$file
done
I have been experimenting further, what if I needed to check for directories or found a new file in a subdirectory that did not exist outside my development directory. I tried dropping the type -f from the find but I keep getting weird results. At one point I had it putting everythign where it needed to be, but an additional copy of each file was also copied to the base directory of my source directory. Somehow I thought when I first decided on this that it would be a little easier.

Last edited by scotbuff; 01-19-2007 at 02:38 PM..
    #4  
Old 01-22-2007
sb008 sb008 is offline Forum Advisor  
Registered User
 
Join Date: Jan 2007
Posts: 398
Thanks: 1
Thanked 3 Times in 3 Posts
find . -mtime -1 -depth -print | cpio -pdmuv ../common

The -o and -p option don't go together.


By using the -depth option the directories will have to same time stamp as the original directory. Basically in this way the directory is copied after the files below it. (Ofcourse the directory is created before, but permissions and access rights, time stamps are copied after).

When doing it the other way around, copying the file will result in the timestamps of the directory to be changed.
Sponsored Links
    #5  
Old 01-23-2007
Registered User
 
Join Date: Jun 2005
Location: Middletown, PA
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Excellent

That is excellent, The -depth on the find command and the straightening out of the cpio flags seemed to be what was causing my problems. Thanks for the response!
Sponsored Links
Closed Thread

Tags
cpio

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to delete the older files other than the recently added 5 files shaal89 Shell Programming and Scripting 5 02-22-2012 02:42 PM
subtring and copy recently files and another folder javeiregh Shell Programming and Scripting 2 11-24-2011 03:14 PM
Find recently changed files raghu_shekar UNIX for Dummies Questions & Answers 3 07-06-2010 05:26 AM
recently updated files shantanuo UNIX for Dummies Questions & Answers 6 09-27-2008 03:22 AM
way to copy only changed files zuessh AIX 3 12-15-2006 02:41 PM



All times are GMT -4. The time now is 09:21 AM.