Operating System - HP-UX
1846597 Members
2637 Online
110256 Solutions
New Discussion

Re: urgent script help again

 
SOLVED
Go to solution
Kenn Chen
Advisor

urgent script help again

i would like to remove my directory files which past over 3 days. how could i write a script to do it ??
e.g.
/tmp/010823.txt
/tmp/010824.txt
/tmp/010825.txt
/tmp/010826.txt
/tmp/010827.txt

i would like to delete first 2 lines (past 3 days).
Cyber Zen
3 REPLIES 3
Thierry Poels_1
Honored Contributor
Solution

Re: urgent script help again

Hi,

something like this will do:

find /tmp -mtime +2 -type f -exec rm -f {} \;

or if you want to narrow it down to specific files:
find /tmp -mtime +2 -name '*.txt' -type f -exec rm -f {} \;

good luck,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Herve BRANGIER
Respected Contributor

Re: urgent script help again

Hi,

I think you can use date :
date +%o%m%d give you 010827

(man date)

You can use date +%o to have year, ....
and after you can compare and find an
alogrithm to delete your files...

HTH

Herv?
Magdi KAMAL
Respected Contributor

Re: urgent script help again

Hi Idris,

Here is :

#find /tmp -mtime +3 -type f -exec rm -f {} \;

+3 is a multiple od 24 hours.

Will delete files older that 72 hours.

Magdi