Reputation: 1422
I have a directory called direct
and it contains 14 million files that have the form file54.txt , where the number 54 in name file54.txt could be replaced by any natural number between 1 and 14 million. Is there a way to split those files into for example 1000 sub-directories in the directory titled direct
that contain in total all of the 14 million files?
Upvotes: 0
Views: 1257
Reputation: 18864
#!/bin/bash
for (( i=0; i < 14000000; ++i )); do
(( dirname=i/14000 ))
if (( i%14000 == 0 )); then
mkdir -p direct/$dirname
fi
mv direct/file$i.txt direct/$dirname/file$i.txt
done
Upvotes: 2