Skip to content
Advertisement

split directory with 10000 files into 2 directories [closed]

I have directory /logos which contains approximately 10000 png images. Can you please suggest some script to make two new folders /logos-1 and /logos-2 each one with half of the images from initial folder?

Thank you in advance <3

Advertisement

Answer

One approach could be to iterate over the files in the folder, keep and counter and move they files the other directory on each iteration:

counter=0
mkdir -p logos-0
mkdir -p logos-1
for file in logos/*
do
  [ -e "$file" ] || continue
  echo mv "$file" "logos-$((counter++%2))/"
done

Remove the echo if the mv commands looks appropriate.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement