I have this script to delete old backup files older than 15 days

"find $path -type f -mmin +".(60 * 24 * $expire_days)." -name '*.tar.*' -delete"

After that I want to keep only 1 backup file per day after 10 days.. How to do that? The backup process runs multiple times a day and creates 4-5 files per day


Well, you'd have to write another script, which,

  1. Enumerates all the files, and for each file collects their pathname last modified time (mtime).
  2. From each mtime, it extracts the date part and ignores the time part.
  3. Then it scans the resulting dataset to identify the groups of entries having the same date; for each such group, you mark all the entries except (any single) one.
  4. Walk through all the marked entries and delete the corresponding files.

As you can see, this is a (reasonably simple) programming task. I'd probably pick Python or Tcl as mere shell scripting won't probably cut it.

  • If you will have a concrete problem with the outline I presented, consider posting to SE.stackexchange.com.
  • If you will have a concrete problem with a particular algorythm while implementing your solution on using a particular runtime/language, consider posting to SO.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.