1833894 Members
1616 Online
110063 Solutions
New Discussion

find and copy

 
SOLVED
Go to solution
Animesh Chakraborty
Honored Contributor

find and copy

Hi,
I want to find & copy only those files which are created or modified between 24th March to 30th March from /usr1 to /usr2.
Waiting for the best commad.

Thanks
Animesh
Did you take a backup?
5 REPLIES 5
Trond Haugen
Honored Contributor
Solution

Re: find and copy

Interesting problem. Here are my 2c.
mkdir /tmp/YY
touch -t 03240001 /tmp/XX
find /usr1 -newer /tmp/XX | cpio -pdumv /tmp/YY
touch -t 03300001 /tmp/YY
find /tmp/YY -newer /tmp/XX -exec rm {} \;
cd /tmp/YY
find . -print | cpio -pdumv /usr2

My thought is this. Find all files newer than Mar 24, copy those to a temp dir (using cpio to maintain date), find and remove files newer than Mar 30 and finally copy those to the destination.

Regards,
Trond
Regards,
Trond Haugen
LinkedIn
Stefan Schulz
Honored Contributor

Re: find and copy

Hi,

if you mean this year and you will do this on March the 30th then i would do the following.

touch 03240001 testfile
find /usr1 -type f -newer testfile -exec cp -p {} \; /usr2

The touch command creates a new file with the timestamp of 24th March 00:01 (one minute after Midnight).

If you do this for last year or any other timeperiod i think combining several mtime statements will help. Something like:

find /usr1 -type f -mtime +10 -a -mtime -17 -exec ....

This should find every file modified between 10 days ago and 17 days ago.

Hope this helps

Regards Stefan
No Mouse found. System halted. Press Mousebutton to continue.
S.K. Chan
Honored Contributor

Re: find and copy

You can actually do this in one shot ..

1) create 2 reference file (Mar23 and Mar30)
# cd /tmp
# touch 03230000 ref1
# touch 03300000 ref2

2) use the negate statement in expression of the find command to get the files you need.

# cd /usr1
# find . \( -newer ref1 -a ! -newer ref2 \) | cpio -pdumx /usr2

It should work, at least close to what you want.
S.K. Chan
Honored Contributor

Re: find and copy

..oops , sorry..the path of ref1 & ref2 ..

# cd /usr1
# find . \( -newer /tmp/ref1 -a ! -newer /tmp/ref2 \) | cpio -pdumx /usr2

Animesh Chakraborty
Honored Contributor

Re: find and copy

Hi,
I will be doing it on coming 31st March
for this year only.
Thanks
Animesh
Did you take a backup?