Skip to content

Instantly share code, notes, and snippets.

@iAnatoly
Created June 15, 2017 12:50
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 iAnatoly/ef7c07b6f944e6e99c5c4117816589ae to your computer and use it in GitHub Desktop.
Save iAnatoly/ef7c07b6f944e6e99c5c4117816589ae to your computer and use it in GitHub Desktop.
Interruptible script generating pre-defined number of random files
#!/bin/bash
TARGET_FILE_NUM=10000
CURRENT_FILE_NUM=`ls -l | wc -l`
FILES_TO_GENERATE=$((TARGET_FILE_NUM - CURRENT_FILE_NUM))
MAX_FILE_SIZE=8192
FILE_NAME_PREFIX="test_"
if [[ $FILES_TO_GENERATE -lt 0 ]]; then
echo "We already have $CURRENT_FILE_NUM files, no need to generate more"
exit
fi
echo "Generating $FILES_TO_GENERATE more files in order to acheive the goal of $TARGET_FILE_NUM"
for i in $(seq $CURRENT_FILE_NUM $TARGET_FILE_NUM);
do
printf "."
if [ $((i % 100)) -eq 0 ]; then
printf $i
fi
uuid=`uuidgen`
newname="${test}${uuid}"
size=$(( (RANDOM % MAX_FILE_SIZE) + 1 ))
head -c $size </dev/urandom > $newname
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment