Operating System - HP-UX
1819804 Members
3170 Online
109607 Solutions
New Discussion юеВ

Using rm on file with certain date/timestamp

 
Maarten van Maanen
Regular Advisor

Using rm on file with certain date/timestamp

I want to use the rm command to delete Oracle *.ARC files if they have reached a certain age or if they are from a certain date. I tried to do this with ll *ARC |grep 'Aug 2'| rm -i but something like that doesn't work. I am probably putting the command in the wrong order but seem to be unable to figure out the correct syntax.
Can anyone give me a hand here ?
10 REPLIES 10
Andreas Voss
Honored Contributor

Re: Using rm on file with certain date/timestamp

Hi,

i think the best is to use find:
Example:
Find all files that arte older than one week and remove them:
find -type f -mtime +7 -exec rm -f {} \;

help for your wish:
ll *ARC |grep 'Aug 2'|awk '{system("rm -f " $NF);}'

Cheers

Andrew

John Palmer
Honored Contributor

Re: Using rm on file with certain date/timestamp

find is definitely you best bet for this.
Either use the -mtime argument to select files a number of days old or you could use the timestamp of an existing file and use the -newerm argument.

Regards,

John
James R. Ferguson
Acclaimed Contributor

Re: Using rm on file with certain date/timestamp

Maarten:

If you choose John's method, you can always make a reference file by touch(ing) it with the timestamp you choose, as for example:

# touch -m -t 08090606 /tmp/f

which would create a file dated August 9, 2000 at 06:06.

...JRF...
Andreas Voss
Honored Contributor

Re: Using rm on file with certain date/timestamp

Hi,

BTW why do you remove the archive files manually ?
If you have OmniBack you can backup the files and remove them within the OmniBack backup specification, ie. Oracle 8:
rman script:
....
"archivelog all delete input"
";"
.....

Regards

Andrew
Maarten van Maanen
Regular Advisor

Re: Using rm on file with certain date/timestamp

Am trying to use find but don't seem to get it working
Directory of logfiles is: /logdisk01/oradata/arch/C2P#. The old files have a .ARC extension.

Example listing:
rw-r----- 1 oracle users 52429824 Aug 9 15:01 T0001S0000012927.ARC
-rw-r----- 1 oracle users 52429824 Aug 9 15:05 T0001S0000012928.ARC
-rw-r----- 1 oracle users 52429824 Aug 9 15:11 T0001S0000012929.ARC

I go there with cd and do a find . -name *ARC and get nothing.
If I do a find ./ -name T* I get:
find: missing conjunction.

What am I missing here ??

Andreas Voss
Honored Contributor

Re: Using rm on file with certain date/timestamp

Hi,

if you are using metachars like * within find you have to quote this:
find ./ -name 'T*'

Regards

Andrew
John Palmer
Honored Contributor

Re: Using rm on file with certain date/timestamp

Or escape them with a backslash character.

E.g find . -name T!*
(read the backslash character for ! above).

Regards,

John
\ \
Victor BERRIDGE
Honored Contributor

Re: Using rm on file with certain date/timestamp

Hi Maarten,
If you wish to use ll, then in order to get rid of whats before the filename you will have to use cmd cut:
# rm $(ll | grep " Aug 2" | cut -c 58-80)
But remember, in this the spaces of what is in between your doublequotes are important:
"Aug 2" vs " Aug 2 " (2 spaces between b & 2)

Hope this helps
Greetings
Victor
James R. Ferguson
Acclaimed Contributor

Re: Using rm on file with certain date/timestamp

Maarten:

Andreas approach using ll|grep|awk does not appear to work if the 'rm' command is specified with any option, like '-f'. Using a simple 'rm' in the command string will work, however. This, at least, on 10.20.

If you prefer to use the more standard (less creative!) approachs, do:

# cd /ora_arch #...or whatever for you...
# find *.ARC -mtime +7 -exec rm -f {} \;

-or-

# cd /ora_arch
# touch -m -t 08030000 f.$$
# find *.ARC -newer f.$$ -exec rm -f {} ;
# rm f.$$

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Using rm on file with certain date/timestamp

Maarten:

OOPS. Look carefully at Andreas' example. The "rm -f " syntax works perfectly fine if you put a BLANK after the 'f' and before the quote (OBVIOUSLY!!!). My apologies for any confusion.

...JRF...