I've been trying to group a big list of txt files into sub folders, each containing random 5 files. I.e. pick 5 random files, create a new folder Group X, and move them to it.
Any help is appreciated. Thanks.
答案 0 :(得分:0)
This is fairly straightforward:
#!/bin/bash
mkdir -p groupX
for i in `seq 1 5`;
do
files=($( ls *.txt ))
RAN=`expr $RANDOM % ${#files[@]}`
echo Moving "${files[$RAN]}" to folder groupX
mv "${files[$RAN]}" groupX
done
Warning, this does no checking if there are less than 5 txt files in the directory.