Saturday, 26 April 2008

Organise Files by Size

I had the problem of about a million recovered files, some scraps, in a single folder. File management doesn't scale well to a million files; so this script reorganises the contents by file size. In this case it uses a scale from 10Mb to 0 in 100k increments.

organisebysize.sh

for i in `seq 10000 -100 0`
do
mkdir "$i"k
mv -v $(find -maxdepth 1 -type f -size +"$i"k) "$i"k
rmdir "$i"k
done

Alternate

Of course even this had scale problems for so many files. My final fix was a command to generate a batch file.

find -type f -printf "mkdir %bblocks; mv %p %bblocks \n" > ../movefiles.sh

0 comments:

iantheteacher

Planet ILUG