#!/bin/sh TMP="/tmp/`basename $0`.$$" TMPa="/tmp/`basename $0`.$$a" TMPb="/tmp/`basename $0`.$$b" target=719680 ordered=true move=false while getopts 67cdmrs: opt;do case $opt in 6) target=666000;; 7) target=720000;; c) target=719680;; d) target=4596992;; m) move=true;; r) ordered=false;; s) target=$OPTARG;; esac done shift `expr $OPTIND - 1` if $ordered;then cds=1 if $move;then mkdir $cds fi total=0 for file in "$@";do size=`du -Lks "$file"|cut -f1` total=`expr $total + $size` if [ "$total" -gt $target ];then echo total: `expr $total - $size` echo echo total=$size cds=`expr $cds + 1` if $move;then mkdir $cds fi fi echo "$file" if $move;then mv -i "$file" $cds fi done echo total: $total echo echo echo ===== echo $cds cds else du -Lks "$@" | sort -nr > $TMP # eliminate files > target while [ "`head -n1 $TMP | cut -f1`" -gt "$target" ];do echo "File `head -n1 $TMP | cut -f2` is too big for target media." >&2 sed 1d $TMP > $TMPa mv $TMPa $TMP done total=0 cds=1 if $move;then mkdir $cds fi while [ `cat $TMP | wc -l` -gt 0 ];do max=`expr $target - $total` { echo $max ; cat $TMP; } | { lineno=1; read max while read line;do size=`echo "$line" | cut -f1` if [ $size -gt $max ];then lineno=`expr $lineno + 1` else echo "$line" sed ${lineno}d $TMP > $TMPa mv $TMPa $TMP break fi done } > $TMPb size=`cat $TMPb | cut -f1` name=`cat $TMPb | cut -f2` if [ "$name" = "" ];then echo total: $total echo echo total=0 cds=`expr $cds + 1` if $move;then mkdir $cds fi else echo -e "$size\t$name" if $move;then mv -i "$name" $cds fi total=`expr $total + $size` fi done echo total: $total echo echo echo ===== echo $cds cds rm $TMP $TMPb fi