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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

shell script to delete files older than 30 days 2

Status
Not open for further replies.

ady2k

Vendor
Jan 28, 2002
463
ID
I would like delete log files older than 30 days and use crontab to do it.
Any shell script expert can provide delete files older than 30 days script to me?
Thanks for advance....:)
 
You really don't even need a script, just add a one
liner to cron directly:

15 1 * * 1 find <pathname> -mtime +30 | xargs rm -f

or

15 1 * * 1 find <pathname> -mtime +30 -exec rm -r {}\;

Will remove all any files or directories under <pathname> older than 30days on Mondays at 1:15 am.

pathname of course can be a directory or files or wildcards, etc...
 
No script required, just:

find <top_level_of_req_directory> -mtime +30 -exec rm {} \;

replace the -exec rm {} \; with -print to ensure that you're deleting the files you want first, as added security. HTH.
 
jmtuser:

It's called simultaneous posting. It happens.

I gave you each a star!

Regards,


Ed
 
Can anyone write a script that stops people from saying/typing Yo and dude?

--
| Mike Nixon
| Unix Admin
|
----------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top