Experimente este script (coloque-o dentro da pasta principal).
#!/bin/bash
echo New dimension?
read dimension
initialDimension=$(du -sk | cut -f1 -d ' ') #Find initial dimension
while [ "$(du -sk | cut -f1 -d ' ')" -gt $dimension ] #While the dimension of this
#Directory is greater then $dimension (inputted before)
do
echo Finding file
#This let you find the oldest file name:
uselessChars=$(find -type f -printf '%T+ %p\n' | sort | head -n 1 | cut -d ' ' -f 1)
oldestFile=$(find -type f -printf '%T+ %p\n' | sort |head -n 1)
oldestFile=${oldestFile#$uselessChars}; #Remove useless chars
oldestFile=${oldestFile# } #Remove useless space
echo " Found: $(find -type f -printf '%T+ %p\n' | sort | head -n 1)" #Print complete path
$(rm "$oldestFile") #Remove the file
echo Removed $oldestFile #Print the result
done
#The result:
echo Done
echo Initial Dimension: $initialDimension
echo Final Dimension: $(du -sk | cut -f1 -d ' ')
Eu acho que essa tarefa poderia ter sido mais fácil com python, mas eu queria tentar escrevê-lo no bash. Muitas coisas poderiam ter sido feitas muito melhor, mas funciona.