target_number=1 target_folder="folder "$target_number"/" #set up the switch folder function, not working correctly yet though file_count=$(expr $(\ls ${target_folder} | wc -l) - 3) #count the number of files, too slow so need to remplace with counting transfer. inotifywait -m -q -e close_write --format %f . | while IFS= read -r file; do #watch a directory/folder for files that have their file descriptor closed, then read the filename of the file printed by inotifywait. if [ file_count=>400000 ]; then #if the file count exceed 400k (or transfer in the preferred case) #change folder here target_number=$((target_number + 1)) #folder scheme is mostly folder1 folder2 etc file_count=$(expr $(\ls ${target_folder} | wc -l) - 3) #used the same function twice, i'm dumb fi move ${file} ${target_folder} #move files but really can be doing anything else than this file_count=$(expr $file_count + 1) #i think i might need to delete that, not sure done