I recently wanted to delete all but the most recent 3 daily backup files. Deleting based on timestamp isn’t safe in this case; if you delete files older than 3 days then you’ll lose all backup files if the backup stops creating new backups for some reason. It’s relatively easy to work with files older or newer than a particular date but it’s less obvious how to deal with the N oldest or newest files, regardless of absolute timestamp, without writing a script.
[Read More]