Delete 2 months before old files when we get alarm directory size > 90%

Please Help me

Question: - we manually moving/removing old files, when we are getting alarm as /dir1/dir2 size greater than 90%.
we manually moving/removing old files and reduce the file size to less than 90%

  • I want to delete all 2months before old files once we get the thresh hold >= 90% in a single unix commands (or) background script delete old files automatically once we get the thresh hold >= 90%

I need your support

You can setup a cron job, and check regularly the size of /dir1/dir2 using the du command, and remove/move the files in that directory when its size reaches the threshold.

Hi,

U can use

ls-ltr

will lists the latest at top most, then you can use | and rm to remove

Vasanth

disk_usage=`df -k . | tail -1 | awk '{printf("%0.2d",$5)}'`; [ "$disk_usage" -gt "90" ] && find <givethepath> -type f -mtime +90 -exec rm {} \;   || echo "we are fine"