Created
June 15, 2017 12:50
-
-
Save iAnatoly/ef7c07b6f944e6e99c5c4117816589ae to your computer and use it in GitHub Desktop.
Interruptible script generating pre-defined number of random files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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