Last active
March 12, 2023 02:37
-
-
Save sputnick-dev/1d2303e5fb75af8792f828ff33c127af to your computer and use it in GitHub Desktop.
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 | |
# https://stackoverflow.com/a/13401143/465183 | |
# Decimal ASCII codes (see man ascii) | |
ARR=( {48..57} {65..90} {97..122} ) | |
# Array count | |
arrcount=${#ARR[@]} | |
# return a random string | |
get_rand_dir(){ | |
for ((i=1; i<$((RANDOM%30)); i++)) { | |
printf \\$(printf '%03o' ${ARR[RANDOM%arrcount]}); | |
} | |
} | |
dir=/tmp/rand_dirs/ | |
# appending random characters to make a hierarchy | |
for ((i=0; i<$((RANDOM%100)); i++)) { | |
dir+="$(get_rand_dir)/" | |
} | |
echo "$dir" | |
mkdir -p "$dir" | |
cd "$dir" | |
while [[ $dir ]]; do | |
dir=${dir%/*} | |
cd $dir | |
for ((i=0; i<$((RANDOM%100)); i++)) { | |
mkdir &>/dev/null -p /tmp/rand_dirs/$(get_rand_dir) | |
} | |
done | |
tree /tmp/rand_dirs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment