Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting Files using date option 3

Status
Not open for further replies.

viclap

Programmer
Oct 12, 2000
39
PH
Hi to all,

I'm having a hard time figuring out on how to delete files (remove) from a directory wherein the scope is from current date to previous dates (30 days). The script will be used for file maintenance of log files which are not needed anymore.

Any help will be highly appreciated.
Thanks in advance.















 
man find

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Before posting it's always a good idea to do a quick search of the site. Had you done so you would have found faq80-5793 - which answers your question

Ceci n'est pas une signature
Columb Healy
 
Here's what we are using to delete e.g. all .arc files older than 2 days:

find /u01/app/archivelog/ -name *.arc -mtime +2 -exec rm {} \;

Just modify the command according to your needs and it should do the trick.

At least this works under AIX ...

Regards
Thomas
 
Just to modify Thomas' post slightly, using wildcards in the -name clause would require single quotes, so *.arc would need to be '*.arc'.

You might also consider the belt and braces safety provided by doing a dummy run using -exec ls rather than rm, just to confirm that the correct files will be picked up.

I want to be good, is that not enough?
 
Hey Guys,

Should this work for XP Pro? Here is what I'm using:
find C:\datfind -name '*.dat' -mtime +3 -exec rm {} \;


But I get:
File not found - '*.dat'


 
Um, BenJMF - this is Unix scripting, Win XP Pro is so far removed from Unix, that if the "find" command would work in Windows even remotely, I would be surprised.

Einstein47
“Evil abounds when good men do nothing.“ - Nelson R.
[[]Starbase47.com]
 
Thanks for the clarification.

I just stumbled across this and thought it would be useful but I don't know much about scripting so I thought i'd ask before I pulled any hair out trying to get it to work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top