Answers:
以下对我来说效果很好。在终端中打开目录,然后复制并粘贴以下脚本,然后按Enter。将在内部创建名为dir_001,dir_002等的子目录。
i=0;
for f in *;
do
d=dir_$(printf %03d $((i/100+1)));
mkdir -p $d;
mv "$f" $d;
let i++;
done
这将提示您需要多少个目录和子目录前缀。ls命令仅提醒您拥有多少文件。
ls -1 | wc -l
read -p 'How Many Directories: ' F;
read -p 'Sub-Directories Prefix: ' S;
PARRENT=${PWD}
# cd $PARRENT
n=0
for i in *
do
if [ $((n+=1)) -gt $F ]; then
n=1
fi
todir=$PARRENT/"$S"_$n
[ -d "$todir" ] || mkdir "$todir"
mv "$i" "$todir"
done
来源:https://www.unix.com/shell-programming-and-scripting/248539-split-folder-huge-number-files-n-folders.html