Computing.Net > Forums > Unix > deleting files older than 2 days

deleting files older than 2 days

Reply to Message Icon

Original Message
Name: anukta_c
Date: December 24, 2002 at 04:31:01 Pacific
Subject: deleting files older than 2 days
OS: HP-UX
CPU/Ram: -
Comment:


Hi,

I want to delete files which had been created 2 days ago having names like:
er_n5412_output_yyyymmdd.csv.processd
from the directory /opt/apps/ccba/dev/callftp/cps_adhoc.
There will be several other files in the same directory which I would not want to delete.

There might be files having names like er_n5412_output_yyyymmdd.csv, these I will not want to delete.

I want to write a script to do this.

I know this can be done with find command, but I cannot get the syntax right.Also, is it possible to explicitly mention the path and the file name matching pattern?

Can anyone help?

-Anukta


Report Offensive Message For Removal


Response Number 1
Name: Sun
Date: December 24, 2002 at 08:17:08 Pacific
Subject: deleting files older than 2 days
Reply: (edit)

find /-name er_n5412_output_yyyymmdd.csv.* \
-atime 2 -exec rm {} \;


Report Offensive Follow Up For Removal

Response Number 2
Name: anukta_c
Date: December 27, 2002 at 02:01:12 Pacific
Subject: deleting files older than 2 days
Reply: (edit)


Thanks, but it is not working with the '*' in there. When I mention the exact file name, it works, but pattern matching did not work.
Any other ideas?

-Anukta


Report Offensive Follow Up For Removal

Response Number 3
Name: David Perry
Date: December 27, 2002 at 08:16:28 Pacific
Subject: deleting files older than 2 days
Reply: (edit)

Some systems require pattern matching in find to be quoted with either single or double quotes.

Try

find / \
-name 'er_n5412_output_yyyymmdd.csv.*' \
-atime 2 -exec rm {} \;


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: deleting files older than 2 days

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge