0

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.

0

1 Answer 1

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

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.