Skip to content

Instantly share code, notes, and snippets.

@ramazanpolat
Last active December 26, 2015 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramazanpolat/7220927 to your computer and use it in GitHub Desktop.
Save ramazanpolat/7220927 to your computer and use it in GitHub Desktop.
This script generates random file names with random contents.
if [ $# -ne 3 ]
then
echo "This script generates random file names with random contents"
echo "USAGE : $0 [prefix] [size] [count]"
echo " prefix : prefix of file name to be generated"
echo " size : size of the file eg. 2048, 100k, 13M"
echo " count : number of files to be generated"
echo "EXAMPLE:"
echo " $0 tmp 10k 3"
echo " will generate 3 files having size of 10 KBytes each and named something like:"
echo " tmp499abbd3.rand"
echo " tmpd88f2e50.rand"
echo " tmp9602da57.rand"
echo " "
echo "Author: Ramazan POLAT - ramazanpolat@gmail.com"
exit 1
fi
PREFIX=$1
SIZE=$2
COUNT=$3
echo "prefix = $PREFIX"
echo "size = $SIZE"
echo "count = $COUNT"
echo "generating $SIZE sized $COUNT files having names starting with $PREFIX..."
for (( i = 1 ; i <= $COUNT; i++ ))
do
#STR1=$(date +%N)
STR2=$(echo $RANDOM$(date +%N) | md5sum)
STR3="${STR2:1:15}"
FILE="./$PREFIX$STR3.rand"
#echo $FILE # show file name
dd if=/dev/urandom of=$FILE bs=$SIZE count=1 &> /dev/null
#echo " file $i / $COUNT is : $FILE"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment