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 creat
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