LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Auto Delete oldest files @ratex when directory is 98% full (https://www.linuxquestions.org/questions/linux-software-2/auto-delete-oldest-files-%40ratex-when-directory-is-98-full-310058/)

jmanjohn61 04-05-2005 02:57 PM

Auto Delete oldest files @ratex when directory is 98% full
 
I need something to delete files when the drive/partition is 98-99% full. The automatic delete needs to run regularly. Anyone have any ideas?

homey 04-05-2005 03:44 PM

Maybe a script which looks at the percent used.....
num=`df -h /home |grep "/dev" | awk '{print$5}'`

If that percent is greater than some number....
if [ $num -gt some_number ]; then

Then use find to remove files which are older than a particular age....
find /home -type f -name '*.jpg' -mtime +90 -exec rm {} \;

Then put the script in a cron job to run when you want.


All times are GMT -5. The time now is 01:50 AM.