, stat awk. , :
find /PATH/TO/FILES -name '*.tar' -type f \
| sed 's/ /\\ /g' \
| xargs stat -f "%a::%z::%N" \
| sort -r \
| awk '
BEGIN{curSize=0; FS="::"}
{curSize += $2}
curSize > $X_SIZE{print $3}
'
| sed 's/ /\\ /g' \
| xargs rm
, , .
find, , , 3 . sed, - , , xargs stat . -f "% a::% z::% N" stat , , . "::" , . -r, .
Now we have a list of all the files that interest us, so that the last one has access to the earliest access. Then the awk script sums up all the sizes as it goes through the list and starts to print them when it gets more than $ X_SIZE. Files that are not displayed in this way will be saved, other file names will be sent to sed again to avoid any spaces, and then to xargs, which starts them rm.
source
share