1

How to delete previous year June files from the list

#!/bin/bash
echo "hi"
path="/home/alert/VideoApplicationAPI.v1/logs"
dayDiff=365

DATE=`date +%Y-%m-%d`
for filename in $path/*.*; do
    modDate=$(stat -c %y "$filename") 
    modDate=${modDate%% *} 
    echo $filename:$modDate
    echo "( `date -d $DATE +%s` - `date -d $modDate +%s`) / (24*3600)" | bc -l
done
echo $DATE
Romeo Ninov
  • 17,484

1 Answers1

1
touch -d '2018-06-01 00:00:00' START
touch -d '2018-07-01 00:00:00' END
find <path of files to be deleted> -type f -newer START -not -newer END -exec rm {} \;

The start and end will give you the date range. That is 2018 June. You can first run only find command, to see what all files you get. If the files are correct, then execute the above command. Make sure you have a back up of all the files, in case if something goes wrong while execution.