Operating System - HP-UX
1752452 Members
6193 Online
108788 Solutions
New Discussion юеВ

Copy files with particular time stamp??

 
SOLVED
Go to solution
Manikandan R
Valued Contributor

Copy files with particular time stamp??

I have a requirement to copy all files in a dir with time stamp in the month of march and tar it...
Is there a simple sol??
9 REPLIES 9
Peter Godron
Honored Contributor

Re: Copy files with particular time stamp??

Hi,
an number of solutions are available.

Some are detailed in:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1048222

My personal preference would be the touch/find solution

Please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.
Manikandan R
Valued Contributor

Re: Copy files with particular time stamp??

I dont want to just list...... I want to copy files with march time stamp to a different dir .....Give me the exact command pls
Peter Godron
Honored Contributor
Solution

Re: Copy files with particular time stamp??

Hi,
# touch -amt 200703010000 /tmp/f1
# touch -amt 200703312359 /tmp/f2
# mkdir /tmp/tardir
# find /pathdir -xdev -type f -newer /tmp/f1 -a ! -newer /tmp/f2 -exec cp {} /tmp/tardir/ \;
# tar -cvf march.tar /tmp/tardir

Univer_1
Valued Contributor

Re: Copy files with particular time stamp??

Just copy them to the new directory, touch them with new time and tar them at last:

cp -r DIR /tmp
touch -t 02010000 $(ls /tmp/DIR/*|tr -d :)
cd /tmp/DIR
tar cvf DIR.tar .
Mobeen_1
Esteemed Contributor

Re: Copy files with particular time stamp??

Some one correct me if i am wrong...but it would not possible to copy files along with the timestamps with pure "cp" command.

How ever, work arounds could be deployed as suggested in posts prior to mine.

regards
Mobeen
Manikandan R
Valued Contributor

Re: Copy files with particular time stamp??

Thanks for your replies.....
Dennis Handly
Acclaimed Contributor

Re: Copy files with particular time stamp??

>Univer: touch them with new time and tar them

I'm not sure why you want to touch them?

>Mobeen: but it would not possible to copy files along with the timestamps with pure "cp" command.

cp -p will save the the permissions, times, etc..
Mobeen_1
Esteemed Contributor

Re: Copy files with particular time stamp??

I am sorry, i meant search .. search based on timestamp...not copy :)

regards
Mobeen
Mobeen_1
Esteemed Contributor

Re: Copy files with particular time stamp??

I will post a new thread, what i meant was unlike other OS once a file is touched ....we will not have track of the file creation date...as the file creation date/time changes from initial date to the date on which it was touched....

For example in OpenVMS we would have file creation date and file modification date...

Thanks guys
Mobeen