max_k=1000
sum=0
target_dir_path="/target/dir"
find . -mindepth 1 -maxdepth 1 -type f -printf '%k %pmax_k=1000
sum=0
target_dir_path="/target/dir"
find . -mindepth 1 -maxdepth 1 -type f -printf '%k %p%pre%' |
while IFS= read -r -d $'%pre%' line; do
size="${line%% *}"
path="${line#* }"
sum=$((sum+size))
if [ "$sum" -le "$max_k" ]; then
printf "%s%pre%" "$path"
else
break
fi
done | xargs -0 echo mv -t "target_dir_path"
' |
while IFS= read -r -d $'%pre%' line; do
size="${line%% *}"
path="${line#* }"
sum=$((sum+size))
if [ "$sum" -le "$max_k" ]; then
printf "%s%pre%" "$path"
else
break
fi
done | xargs -0 echo mv -t "target_dir_path"