Sunday, March 25, 2007

Delete Files older than two Months from the Latest File

This script should Identify the Latest date file and delete files
which are older than 2 Months from latest date.


bash-3.00$ cat delet_old.sh

#!/bin/bash
touch -d "$(date -d "$(ls -lt | awk 'NR==2{print $6,$7}') 2 months ago")" FILE_MARK &&
find . ! -newer FILE_MARK -exec rm -f {} \;

No comments: