Skip to content

Instantly share code, notes, and snippets.

@manchot0
Last active July 26, 2021 10:47
Show Gist options
  • Save manchot0/1b18cb948aca17b5fb2810e761309697 to your computer and use it in GitHub Desktop.
Save manchot0/1b18cb948aca17b5fb2810e761309697 to your computer and use it in GitHub Desktop.
bash archive file
#!/bin/bash
baseDir="/path"
# On compte le nombre d'archive presente dans le dossier
NbArchive=$(ls -A $baseDir | wc -l)
# Si il y a plus de 15 archives, on supprime la plus ancienne
while [ "$NbArchive" -gt 15 ];do
# On recupere l'archive la plus ancienne
Old_backup=$(ls -lrt $baseDir | head -n 2 | tail -n 1 | cut -d ":" -f 2 | cut -d " " -f 2)
# On supprime l'archive la plus ancienne
rm $baseDir/$i/$Old_backup
NbArchive=$(ls -A $baseDir | wc -l)
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment