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!

script for deleting files with age over 30 days

Status
Not open for further replies.

thedarkzone

IS-IT--Management
Mar 19, 2003
3
AT
hi @ all!

i need to write a bash-script for deleting files that are over 30 days old. the entering of the directories and the deleting is working now, but i don't know how to determine the age of a file to know if it should be deleted or must not be deleted!

anybody a solution?

regard, thedarkzone
 
find / -type f -atime 30 -exec rm {} \;
find / -type f -ctime 30 -exec rm {} \;
find / -type f -mtime 30 -exec rm {} \;

- atime (file ACCESSED X days ago)
- ctime (file CREATED X days ago)
- mtime (file MODIFIED X days ago)

I'm not clear how you want to measure you 30 days; 30 days after what?
 
zeland's solution will delete file that are exactly 30 days old. Use

find /mydir -type f -mtime +30 -exec rm {} \;

to delete files more than 30 days old. CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top