Bash : Batch to delete deprecated files

2013-05-15
Laurent Bientz

A small script, written long time ago, that allows you to delete files in a given folder based on their creation date.

#!/bin/sh
# Variables
nbDays=2 # Le nombre de jour au dela duquel vous voulez supprimer les fichiers
password="your_root_password" # Votre password root
currentDate=$(date +%s)
deltaDays=$((86400 * $nbDays))
# Delete /Your/path/pattern_files
for i in /Your/path/*form0_*
  do
    fileDate=$(date -d $(stat -c %y $i | cut -d' ' -f1) +%s)
    if [ $(expr $fileDate + $deltaDays) -gt $currentDate ]
      then
        echo -n $password | sudo -S rm $i
    fi
  done

 

Comment

USER EXPERIENCE

Wandi invites you to discover a new approach to navigating a website...
Are you ready?

Launch the experience