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

Script to erase old files

Status
Not open for further replies.

Eddiefdz

IS-IT--Management
Joined
Mar 20, 2002
Messages
273
Location
US
Hello,

I was wondering what syntax to use if i wanted to write a script to erase older dated files. I have files which i attach the current date as part of the file name. I want a script that will check the name and delete any files that are over 25 days old. Can anyone help me out with this??

Thanks,

Eddie Fernandez
CCNA, Network+, A+, MCP
 
Ok this will find you any files older than 30 days in the specified <path> and <name> ls them for you.
Code:
find <path> -name <name> -type f -atime +30 -exec ls -all {} \;
When you are confident that you can see ONLY what you want to delete then you can modify it to:
Code:
find <path> -name <name> -type f -atime +30 -exec rm {} \;
Or to be in attendence and safe ....
Code:
find <path> -name <name> -type f -atime +30 -exec rm -i {} \;

Carefull !!

Laurie
 
read the man page for 'find', especially the -mtime, -atime and -ctime switches.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top