Last active
July 15, 2024 06:49
-
-
Save jackylamhk/059e9f44908c9d3fe7a1e5370ab4c69e to your computer and use it in GitHub Desktop.
Write random data to disk
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/sh | |
set -euo pipefail | |
if [[ $# -lt 1 || $1 == "--help" ]]; then | |
echo "Usage: $0 <target_path> <size_in_gb> (default: 10)" | |
exit 0 | |
fi | |
GiB_IN_BYTES=1073741824 | |
TARGET_PATH=${1:-"/tmp/random"} | |
SIZE_IN_GB=${2:-"10"} | |
mkdir -p "${TARGET_PATH}" | |
echo "Begining to write ${SIZE_IN_GB} GiB of random data to ${TARGET_PATH}" | |
start_time=`date +%s` | |
for i in `seq 1 ${SIZE_IN_GB}` | |
do | |
file_name=`LC_ALL=C tr -dc A-Za-z0-9 < /dev/urandom | head -c 8 || true` | |
target_file="${TARGET_PATH}/${file_name}.dat" | |
echo "Writing ${i} of ${SIZE_IN_GB} GiB to ${target_file}" | |
head -c "$GiB_IN_BYTES" < /dev/urandom > "${target_file}" | |
done | |
echo "${SIZE_IN_GB} GiB of random data written to ${TARGET_PATH} in `expr $(date +%s) - ${start_time}`s." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment