FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu User

 
 
LinkBack Thread Tools
 
Old 10-24-2011, 10:41 AM
Wipe_Out
 
Default find and cp with directory structure.

Hi,
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..

rsync is no good because I can't limit it to getting files that have changed in the last 30 days only..
Anyone have any suggestions how I can replicate the directory structure as well?

TIA
--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 10-24-2011, 11:00 AM
David Shochat
 
Default find and cp with directory structure.

On Mon, Oct 24, 2011 at 6:41 AM, Wipe_Out
<wipe_out@users.sourceforge.net> wrote:
> Hi,
> 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..
> rsync is no good because I can't limit it to getting files that have changed
> in the last 30 days only..
> Anyone have any suggestions how I can replicate the directory structure as
> well?

Perl's File::Find module is great for this sort of thing, assuming you
know Perl.
-- David

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 10-24-2011, 11:38 AM
Nils Kassube
 
Default find and cp with directory structure.

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.


Nils

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 10-24-2011, 11:47 AM
Steve Flynn
 
Default find and cp with directory structure.

On 24 October 2011 12:00, David Shochat <david.shochat@gmail.com> wrote:
*


Perl's File::Find module is great for this sort of thing, assuming you

know Perl.


You think the File:Find module can be used to create parent directories? I suspect not.
The OP is asking how to copy a file from one directory to another creating the filesystem hierarchy if required. For this you'll need to either create the filesystem first using mkdir -p or pass the --parents parameter to cp.


--
Steve

When one person suffers from a delusion it is insanity. When many people suffer from a delusion it is called religion.


--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 10-24-2011, 12:12 PM
David Shochat
 
Default find and cp with directory structure.

On Mon, Oct 24, 2011 at 7:47 AM, Steve Flynn <anothermindbomb@gmail.com> wrote:
> On 24 October 2011 12:00, David Shochat <david.shochat@gmail.com> wrote:
>
>>
>> Perl's File::Find module is great for this sort of thing, assuming you
>> know Perl.
>
>
> You think the File:Find module can be used to create parent directories?
Of course you can create directories in Perl. You can do anything in
Perl that can be done in the shell.

It should be pointed out that the question and its solutions are
equally applicable to all Unix-like systems, including MacOSX, so
maybe another forum...

It is probably possible to do it with the find command, and I'm going
to investigate the --parents switch that you mention since that's new
to me. I've just found that many things that are tricky with find are
much more straightforward (and in some cases run much faster) using
File::Find.
-- David

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 10-24-2011, 01:27 PM
David Shochat
 
Default find and cp with directory structure.

On Mon, Oct 24, 2011 at 7:38 AM, Nils Kassube <kassube@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

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 10-24-2011, 01:54 PM
Wipe_Out
 
Default find and cp with directory structure.

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

On Mon, Oct 24, 2011 at 7:38 AM, Nils Kassube <kassube@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..*
--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 10-24-2011, 02:43 PM
Wes James
 
Default find and cp with directory structure.

Hi,

On Mon, Oct 24, 2011 at 4:41 AM, Wipe_Out
<wipe_out@users.sourceforge.net> wrote:
> Hi,
> 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 {}

<snip>

Try this: (not fully tested)

# files 30 days old
tar -vpcf - -C `find src_dir -ctime -30` | tar xpf - -C dest_dir

(dest_dir must exist)

or try this:

http://www.linuxquestions.org/questions/linux-general-1/rsync-files-accessed-under-30-days-379378/

with the above rsync solution, you create a file that contains a list
of your files, then rsync the files in that list.

-wes

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 10-24-2011, 05:42 PM
Hal Burgiss
 
Default find and cp with directory structure.

On Mon, Oct 24, 2011 at 6:41 AM, Wipe_Out <wipe_out@users.sourceforge.net> wrote:


Hi,
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..



rsync is no good because I can't limit it to getting files that have changed in the last 30 days only..
Anyone have any suggestions how I can replicate the directory structure as well?



TIA

--

ubuntu-users mailing list

ubuntu-users@lists.ubuntu.com

Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users




Doesn't the -a option do that ...*
*$ find . -mtime +30 -exec cp -av {} $dirname/ *;
That seems to work on my system.*



--
Hal


--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 

Thread Tools




All times are GMT. The time now is 11:22 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org