Hello all,
I'm trying to copy all files within a specified directory to another location based on a find filter of mtime -1 (Solaris OS). The issue that I'm having is that in the destination directory, I want to retain the source directory structure while copying over only the files that have been modified within 24 hours (so cp -r option is out).
For example, if I've got the following directory structure as my source
/datafiles
/datafiles/a/a1.txt (mod 12 hours ago)
/datafiles/a/a2.txt (mod 36 hours ago)
/datafiles/b/b1.txt (mod 36 hours ago)
/datafiles/b/b2.txt (mod 12 hours ago)
And my target is /modfiles, then after the copy I would want the following:
/modfiles/datafiles/a/a1.txt
/modfiles/datafiles/b/b2.txt
I'm trying:
find /datafiles -mtime -1 -exec cp '{}' /modfiles \;
I'm trying to avoid having to use TAR for this to maintain the directory structure but it's starting to look like my only option. Any ideas?
Thanks!
I was not sure of this , how ever googled and end up in the link:
How do I selectively copy files from a directory structure? :: Free Tech Support :: Ask Dave Taylor!
So , you can modify your "find" command something like this:
find /datafiles -mtime -1 | cpio -pavd DESTINATION_DIRECTORY
Let me know , if it worked out!
That's a great solution, so long as he has cpio and none of the filenames contain a newline (usually a sane assumption ;)).
If the OP has cpio but needs to handle filenames with a newline, some implementations of cpio support a -0 option which can be used in conjunction with find's -print0.
Regards,
Alister
This solution does work in regular shells unfortunately the shell I'm using is a custom one from a product that is based on UNIX but does not have the CPIO command which is very unfortunate.
Thank you for the response...I think I may have to look into some alternatives.
Just a quick update on my progress...it seems that the pax utility does the trick so far for what I need:
pax -rw -u -T 0000 -p am /datafiles /modfiles
This seems to copy all files that were modified within 1 day from /datafiles to /modfiles directory and does not preserve mod time (which is what I need).
It also seems to copy over the parent directory structures of the files which is great. Now for some further testing...