find and cp with directory structure.

Wipe_Out wipe_out at users.sourceforge.net
Mon Oct 24 13:54:27 UTC 2011


On 24 October 2011 14:27, David Shochat <david.shochat at gmail.com> wrote:

> On Mon, Oct 24, 2011 at 7:38 AM, Nils Kassube <kassube at gmx.net> wrote:
> > Wipe_Out wrote:
> >> I am trying to keep a directory with only the files that have changed
> >> in the last 30 days (nothing earlier).. I am trying this command..
> >>
> >> find /mnt/Scheduling/ -type f -mtime -30 -exec cp -r {}
> >> /home/ftpuser/attendance_registers/ \;
> >>
> >> I have tried with and without the "-type f" option but it only copies
> >> the files from all directories of the source to the root of the
> >> destination.. Even using "cp -r" made no difference because
> >> obviously find is just passing the filename to the cp command..
> >
> > The find command passes the filename including path, but cp only uses
> > the filename for the destination. If you want to copy the path as well,
> > you could try the "--parents" option to the cp command.
> >
> Hopefully Wipe_Out is all set based on your suggestion. Since you said
> "could try" and "--parents" was new to me, I did try it and it did
> work. It worked with and without "-type f" but complained about the
> directories without it. Also, we do not want the "-r" in the cp
> command, since his point was to copy only some of the files (and
> "-type f" makes it vacuous anyway). Might want a "-p" though to
> preserve timestamps.
> -- David
>
>
Hi all..

The --parents did and didn't work.. Its created the complete structure right
back to / but its no big deal I can just change my script to get the paths
right..

Thanks for all the help..
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20111024/39009308/attachment.html>


More information about the ubuntu-users mailing list