Question: I have a 1000s of files in a directory with and I want to be able to divide them into sub-directories, with each sub-directory containing a specific number of files. I don't care what files go into what directories, just as long as each contain a specific number. All the file names have a common ending (e.g. .txt) but what goes before varies. 

Anyone know an easy way to do this.

Answer: 
```
max_per_subdir=1000
start=1
while [ -e $(printf %03d $start) ]; do
  start=$((start + 1))
done
find -maxdepth 1 -type f ! -name '.*' -name '*.txt' -print0 \
| xargs -0 -n $max_per_subdir echo \
| while read -a files; do
  subdir=$(printf %03d $start)
  mkdir $subdir || exit 1
  mv "${files[@]}" $subdir/ || exit 1
  start=$((start + 1))
done

```
How about 

```
find *.txt -print0 | xargs -0 -n 100 | xargs -I {} echo cp {} '$(md5sum <<< "{}")' | sh

```

This will create several directories each containing 100 files. The name of each created directory is a md5 hash of the filenames it contains.