Skip to content

Instantly share code, notes, and snippets.

@sputnick-dev
Last active March 12, 2023 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sputnick-dev/1d2303e5fb75af8792f828ff33c127af to your computer and use it in GitHub Desktop.
Save sputnick-dev/1d2303e5fb75af8792f828ff33c127af to your computer and use it in GitHub Desktop.
#!/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