Linux: create random directory/file hierarchy
bash, command-line-interface, linux, shell
Solution
I wasn't too happy with the given answers, so I came up with my own. The following takes my input files and uses /dev/urandom to gather 10 to 256 printable chars, puts in a few more directory separators, creates the directory hierarchy and places a file in it.
Using urandom creates some really weird directory names which is good for my purpose. I'm sure a real Unix guru could simplify this even more. The dir building could probably be done in a single awk command for example.
#!/bin/bash
INDIR='files';
IFS=$'\n'
for FILE in `ls $INDIR/*`; do
DIR=`cat /dev/urandom | \
tr -dc '[ -~]' | \
tr 'ABCDEF\\\\' '///////' | \
head -c$((10 + $RANDOM % 256))`
mkdir -p $DIR
cp $FILE $DIR
done
Problem
For testing a tool I need a directory with a whole bunch of different Office files in a deep nested structure. I already have the files in a directory, but now need to create some random nested sub directories and spread out the files in them. I could sit down and write a proper program in a programming language of my choice, but I wonder if there might be a clever combination of Linux command line tools + Bash to achieve what I want. Edit: to clarify, my input is a directory with a about 200 files. The output should be a directory hierarchy containing these files more or less evenly spread. Directory names should be more than single letters, vary randomly in length and use various allowed characters (utf-8 filesystem).