I want to delete log files which are older than 5 days from a directory. But deletion should not be based on the timestamp of file. It should be based on the name of file. For Example todays date is 07/05/2012 and the directory contains 10 files of names like ABC_20120430.log
, ABC_20120429.log
, ABC_20120502.log
, ABC_20120320.log
etc. I want to be able to remove the files by extracting the date from the name of the file.
UNIX – Remove Files Older Than 5 Days with Date in Filename
bashrmsed
Best Answer
Based on date from filename: