Skip to content

Instantly share code, notes, and snippets.

View manchot0's full-sized avatar

Timothe manchot0

  • France, Challans
View GitHub Profile
@manchot0
manchot0 / gist:91c959c45750537e7936a50345af2154
Created July 26, 2021 08:29
powershell archive files on date
#clean recursively all files older than 180 days in the given path
$filterDate = (Get-Date).AddDays(-180).Date
Get-ChildItem E:\DIR_PATH -Directory | ForEach-Object {
Get-ChildItem $_.FullName -Recurse | Where {$_.lastwriteTime.Date -le $filterDate } | Remove-Item
}
#!/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)