System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

how to copy file for a selective date.

SOLVED
Go to solution
ng_7
Regular Advisor

how to copy file for a selective date.

Dear experts,

I have command below to move file to a specified locator for a selective date.

cd /prod/applprod/prodcomn/temp
touch -t 0706010000 /tmp/start
touch -t 0706052359 /tmp/finish
find . -name '*.t' -xdev -type f -newer /tmp/start -a ! -newer /tmp/finish -exec mv {} /sharef/t \;

my question is , how do I modify the script so that it become copy command to /sharef/t ?
I have tried to change mv to cp , but it seems not working.

please help. thanks

regards
ng
4 REPLIES
Kranti Mahmud
Honored Contributor
Solution

Re: how to copy file for a selective date.

Hi ng,

how to copy file for a selective date==>

Yu can do the following:

1. cp /var/adm/syslog/syslog.log /var/adm/syslog/syslog.log_`date +%Y%m%d_%H%M%S`

This will copy the syslog.log appending the current date and time, as for example:

...syslog_20010219_161148

2. set `date +'%d %b %Y'`
DAY=$1
MONTH=$2
YEAR=$3
DATE=$DAY$MONTH$YEAR

Then copy the file to the new location with the $DATE appended to the end.

cp FILE /tmp/FILE.$DATE

3.
# touch -amt 200905040000 /tmp/f1
# touch -amt 200905042359 /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

Rgds-Kranti
Dont look BACK as U will miss something INFRONT!
Suraj K Sankari
Honored Contributor

Re: how to copy file for a selective date.

Hi,

You have to give the {} bracket after the destination directory.

find . -name '*.t' -xdev -type f -newer /tmp/start -a ! -newer /tmp/finish -exec mv /sharef/. {} \;

Suraj
Steven Schweda
Honored Contributor

Re: how to copy file for a selective date.

> I have tried to change mv to cp , but it
> seems not working.

I don't see why it wouldn't work, but my
psychic powers are weak, and so I can't see
exactly what you did, or what happened when
you did it. "seems not working" is not a
useful description of anything.

Is "/sharef/t" a directory?



> [...] -exec mv /sharef/. {} \;

I'm beginning to believe that if you wait
long enough in this forum, someone will
suggest that you stand on one leg and scream
like a chicken.

man mv

Which argument is which?
ng_7
Regular Advisor

Re: how to copy file for a selective date.

sorry, is my mistake. I didn't change *.t to the proper filename. apologize to waste you guy valuable time.