What I am trying to accomplish is I have a directory with lets say 176,000 files. I want the script to split the 176,000 files into folders with lets say 20,000 files each and the last one containing the odd ball #. I would like to copy the files sequentially and keeping them in order alpha numerical. This is what I currently have but it seems to be missing something, the first 2 folders it creates are out of order, the other 3 folders it creates are sequential.
Bottom line, folder contains 176,000 files, script would move the first 20,000 into a folder called 'split' then takes the next 20,000 and so on, creating split2, split3, etc..
Here is what I have:
#!/bin/bash
dir_size=20000
dir_name="split"
n=$((`find . -maxdepth 1 -type f | wc -l`/$dir_size+1))
for i in `seq 1 $n`;
do
mkdir -p "$dir_name$i";
find . -maxdepth 1 -type f | sort -n -z | head -n $dir_size | xargs -i mv "{}" "$dir_name$i"
done