0

This question already has an answer here:

I have 1000 files in a single folder and I need to split them into counts of 100 files each. After this, I need to automatically move the 100 files to a new folder which is automatically created.

I use this command for manually moving the files.

for file in $(ls -p | grep -v / | tail -100);
do 
mv "$file" NEWFOLDER;
done

But, this will be hard enough if I had around 10000 files in a single folder.

marked as duplicate by jasonwryan, Networker, Gilles Quenot, Ramesh, jimmij Jan 20 '15 at 18:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4

I've found the answer in https://stackoverflow.com/questions/10394543/need-a-bash-scripts-to-move-files-to-sub-folders-automatically

#!/bin/bash
c=1; d=1; mkdir -p NEWDIR_${d}
for jpg_file in *.jpg
do
  if [ $c -eq 100 ]
  then
    d=$(( d + 1 )); c=0; mkdir -p NEWDIR_${d}
  fi
  mv "$jpg_file" NEWDIR_${d}/
  c=$(( c + 1 ))
done

try this code

it works great, I've tested it

Not the answer you're looking for? Browse other questions tagged or ask your own question.