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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

deleting files older than 2 days

Reply to Message Icon

Name: anukta_c
Date: December 24, 2002 at 04:31:01 Pacific
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



Sponsored Link
Ads by Google

Response Number 1
Name: Sun
Date: December 24, 2002 at 08:17:08 Pacific
Reply:

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


0

Response Number 2
Name: anukta_c
Date: December 27, 2002 at 02:01:12 Pacific
Reply:


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


0

Response Number 3
Name: David Perry
Date: December 27, 2002 at 08:16:28 Pacific
Reply:

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 {} \;


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Compile World Tool Kit uninstall unix



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: deleting files older than 2 days

Delete Files Older Than 2 Weeks www.computing.net/answers/unix/delete-files-older-than-2-weeks/4564.html

Rename files older than 2 days www.computing.net/answers/unix/rename-files-older-than-2-days/4185.html

How to find file older than 4 hours www.computing.net/answers/unix/how-to-find-file-older-than-4-hours/5145.html