Folders are created every time I (re)boot.
They have the format below: (the time will always vary)
.mozilla_2019_01_08_08:02 .mozilla_2019_01_09_20:16 .mozilla_2019_01_10_01:16 .mozilla_2019_01_10_18:12
Here, I want to be able to delete the folder .mozilla_2019_01_10_18:12 when it is created as an earlier one already exists on ..._2019_01_10. Better would be to stop it being created, i.e. if one has already been created that day.
I can't use cron @daily or specific times as I never know how often or when the computer will be (re)booted.
How can I do this in an existing script please?
Here is my script:
##!/bin/bash ## # COPY .mozilla FOLDER AND LEAVE LAST 10 COPIES (1 per day?) # sleep 30 # if [ -e /home/david/nas-backups/mozilla/ ] then cp -a /home/david/.mozilla /home/david/nas-backups/mozilla/ mv /home/david/nas-backups/mozilla/.mozilla /home/david/nas-backups /mozilla/backups/.mozilla_$(date +%Y_%m_%d_%H:%M) # Show result of copy message export DISPLAY=:0 && zenity --info --title "Backup Information Box" --text=".mozilla Backup Finished Backed up to: /nas-backups/mozilla/backups/" --width=600 --height=200 ## Working on how to keep only first copy per day ## # Limit to last 10 alphabetical copies (courtesy of @Vijay) cd ~/nas-backups/mozilla/backups total=$(ls -1A|wc -l); remove=$((total - 10)); rm -rv $(ls -1vA|head -n $remove) # Show folder so I can manually delete extra daily copies nautilus /home/david/nas-backups/mozilla/backups else export DISPLAY=:0 && zenity --info --title "Backup Information Box" --text=".mozilla backup FAILED - nas-backups either not mounted or not availeble" --width=450 --height=150 fi