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

delete old files

Status
Not open for further replies.

johny2K

Technical User
Dec 19, 2001
184
CA
i just need help re script that delete old files.

i want to auto-delete files if it's older than current date, i.e., three-days, one-week or 2-weeks old.

in a directory - i have several files created on a daily basis. format for files being created is yymmddXX.CCC, where XX & CCC are constant.
 
Hi

This will filter the [tt]ls[/tt] list, outputing only names containing date older then 3 days :
Code:
ls -1 *XX.CC | \
awk 'systime()-mktime(gensub(/(..)(..)(..).*/,"20\\1 \\2 \\3 00 00 00",""))>60*60*24*3'
If you really want to rely on the file name. Otherwise see p5wizard's advise.

Feherke.
 
see FAQ80-5793
It's always worth checking the FAQs in this forum AND the General Unix Discussion

Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top