find and cp with directory structure.

David Shochat david.shochat at gmail.com
Mon Oct 24 13:27:46 UTC 2011


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




More information about the ubuntu-users mailing list