Last active
May 14, 2024 11:09
-
-
Save johnybradshaw/e524cd92b15d735a35baaca329a9bcab to your computer and use it in GitHub Desktop.
Script to create random files in a directory
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 | |
# Location | |
location=/mnt/data | |
# Start size in MB | |
start_size=100 | |
# End size in GB - Note: Bash does not support floating point arithmetic, so we'll work with MB | |
end_size=$((100 * 1024)) # 100GB in MB | |
# Increment size in MB | |
increment=1024 # 1GB increment | |
for ((size = start_size; size <= end_size; size += increment)); do | |
# Calculate the size in MB for files <1GB and in GB for others | |
if [ $size -lt 1024 ]; then | |
size_label="${size}MB" | |
else | |
gb_size=$(($size / 1024)) | |
size_label="${gb_size}GB" | |
fi | |
file_name="random_${size_label}.bin" | |
# Using /dev/urandom to generate random data | |
# bs=1M sets the block size to 1MB, count is how many of those blocks we want | |
echo "Creating file $file_name of size $size_label" | |
dd if=/dev/urandom of=${location}/${file_name} bs=1M count=$size status=progress | |
done | |
echo "File creation completed." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment