Created
August 1, 2016 14:58
-
-
Save davidgiesberg/bcd3ebe0da2ee307eb564d4f6a51b077 to your computer and use it in GitHub Desktop.
Generate a random directory hierarchy
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
#!/usr/bin/env bash | |
# Good source of text to feed in: | |
# curl -s -X POST lipsum.com/feed/json -d "amount=100" -d "what=words" -d"start=true" | jq -r '.feed.lipsum' | |
root_dir="$1" | |
if [ -z "$root_dir" ]; then | |
echo "Usage: $(basename ${BASH_SOURCE}) <root directory>" | |
exit 1 | |
fi | |
if [ ! -d "$root_dir" ]; then | |
echo "${root_dir} does not exist" | |
exit 1 | |
fi | |
echo "Creating bogus hierarchy under ${root_dir}" | |
while read line; do | |
for word in $line; do | |
sanitized_word=$( echo $word | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' ) | |
rand_parent_dir="$(find ${root_dir} -type d | gshuf -n1)" | |
case $(( $RANDOM % 2 )) in | |
0 ) | |
mkdir -p ${rand_parent_dir}/${sanitized_word} | |
;; | |
1 ) | |
touch ${rand_parent_dir}/${sanitized_word} | |
;; | |
esac | |
done | |
done | |
tree $root_dir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment