Splitting folders with large file counts into smaller folders

Ever had a folder with 200000 files and needed to split them into smaller folders? If so, the following code can be executed within the directory from your command prompt (terminal) to split into n directories of 10000 files each:

i=0; 
for f in *; 
do 
    d=dir_$(printf %03d $((i/10000+1))); 
    mkdir -p $d; 
    mv "$f" $d; 
    let i++; 
done

Source: askubuntu.com

Splitting folders with large file counts into smaller folders
Scroll to top