sort files by date, delete oldest, if total size bigger than

hello people
i need your help please

i want to achieve the following with the simplest, most efficient shell-tools:

i have a directory with a lot of files from users.

the script should check which partition the dir is on

if the partition with the directory is more than 90% full

sort files in the directory by date last touched

then delete the 50 oldest files

i have done this in PHP but it is pretty slow now by growing number of files on a 2TB drive.

and in Shell-scripting i am not good at all to achieve this

id be very happy if one of the professionals here could help me.
if you want i write you a little funny poem as a thank you :wink:

peace, Tony

Hi Try this one

bdf|awk '{print $5" "$6}'| while read output;
> do
> sizes=$(echo $output|awk '{print $1}'|awk -F "%" '{print $1}')
> dir=$(echo $output|awk '{print $2}')
> if [ $sizes -ge 90 ]; then
> echo "$dir:$sizes"
> ls -lrt $dir |tail -5
> fi
> done

it is listed any dir which has size greater than 90% and short the latest 5 files in those directory, you may modified it so it will suit with you

thanks, gonna play with this