#!/bin/env bash filecount=$(ls -l | wc -l) echo "File count: ${filecount}" splitby=100 directory_count=$(($filecount/$splitby+1)) echo "Directories to split into: ${directory_count}" echo "--START--" count=0 current_dir=1 test -d $current_dir || mkdir $current_dir overall=0 for file in * do # if [ $overall -eq 20 ] # then # break # fi overall=$((overall+1)) if [ -d "$file" ] then # echo "Not a file, skipping." continue fi echo "Current file: ${file}" count=$((count+1)) if [ $count -gt $splitby ] then current_dir=$((current_dir+1)) count=1 echo "Current count: ${count} (threshold overflow)" mkdir "$current_dir" else echo "Current count: ${count}" fi echo "Moving to: ${current_dir}" mv "$file" "$current_dir" echo "--" done