Random File Creator

Ever need to create a specific amount of files with random content and of random sizes between a specific range ? And all these files randomly placed in a specific maximum number of directories ? Today I needed to do this to replicate a specific scenario and test various things...(blah blah bla)..

Spoiler alert, this is actually easy so if you like solving puzzles don't look, go try and be happy when you'v figured it out... If you are lazy then steal this script.. Check the script's comments for config and extras.

#!/bin/bash # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE # Version 2, December 2004 # # Copyright (C) 2011 Emmanuel Revah <manu@manurevah.com> # # Everyone is permitted to copy and distribute verbatim or modified # copies of this license document, and changing it is allowed as long # as the name is changed. # # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION # # 0. You just DO WHAT THE FUCK YOU WANT TO. ##### Config (uration) ##### # QTY of files to create QTY=1000000 # Where to create new files ? OUTPUT="/home/herebefiles" # Min and Max size per file in kB MIN=1 MAX=10 # Max number of directories to create MAXDIR=500 ############## END CONFIG ############# # Correct MIN and MAX and check MAX=`expr $MAX - $MIN + 1` if [[ ${MAX} < 0 ]]; then echo "ERROR: MAX is lower than MIN, and vice versa." exit fi for i in $(seq 1 $QTY); do echo "File number -> $i" DDCOUNT=$[ ( $RANDOM % $MAX ) + $MIN ] DIR=$[ ( $RANDOM % $MAXDIR ) + 1 ] # uncomment and use "$OUTPUT/$DIR/${i}_$FILENAME" to avoid rewriting over previous random files #FILENAME=`head -n1 /dev/urandom | md5sum| awk {'print $1'}` if [ ! -d $OUTPUT/$DIR ]; then mkdir -p $OUTPUT/$DIR fi dd bs=1024 count=$DDCOUNT skip=0 if=/dev/urandom of=$OUTPUT/$DIR/${i} 2> /dev/null done