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

Determine the age of a file/directory

Status
Not open for further replies.

Muskaan

Programmer
Oct 21, 2002
47
US
Hi,

I wanted to know if there was a one-step command to determine the age of a file, something like months_between(DATE1,DATE2) in oracle. I need to write a purge script that can delete all log files older than 3 months. What is the best way to do that?

Thanks in advance!
Muskaan
 
Use the find command

This lists the *.log files older than 90 days
Code:
find . -name "*.log" -mtime +90 -ls

When you're sure, move on to deleting
Code:
find . -name "*.log" -mtime +90 -exec rm -f {} \;
 
Hey Salem!
This works well for me! Thanks!
Muskaan...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top