Created
January 2, 2018 16:00
-
-
Save karlbaillie/a468c53d6964bb4cc7b62f9cc34c1283 to your computer and use it in GitHub Desktop.
Test File Generator
This file contains hidden or 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 | |
# | |
# A script to generate any number of files with random names and contents | |
# | |
# Usage: generate-test-files.sh (No. of Files) (Size in MB) (Path To Destination) | |
# Example: ./generate-test-files.sh 50 25 ./Folder | |
# | |
# (c) 2017, Karl Baillie <[email protected]> | |
# | |
if [ $# -eq 0 ] | |
then | |
sed -n '3,8p' "$0" | tr -d '#' | |
exit 1 | |
fi | |
for i in $(seq 1 $1); do | |
FILENAME="TestFile_$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1).txt" | |
echo "Creating file $3/$FILENAME" | |
touch $3/$FILENAME | |
dd if=/dev/zero of=$3/$FILENAME bs=1M count=$2 | |
if [[ $? != 0 ]]; then | |
echo "Failed to create $3/$FILENAME" | |
exit 1 | |
fi | |
done | |
exit 0 | |
# EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment