Grouping TXT files

时间:2015-10-30 22:11:21

标签: linux shell unix cygwin

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.

1 个答案:

答案 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.

相关问题