Skip to main content
edited tags
Link
Bernhard
  • 12.6k
  • 5
  • 62
  • 70
Post Migrated Here from stackoverflow.com (revisions)
Source Link
Naren
  • 345
  • 2
  • 3
  • 6

Remove files older than 5 days in UNIX (date in file name, not timestamp)

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.