mk_test_tree
von heisenberg- SNIPPET_DESC:
- Dateibaum aus zufälligen Namen erzeugen
- SNIPPET_CREATION_TIME:
- 09.10.2024 15:32:54
- SNIPPET_PRUNE_TIME:
- Unendlich
- SNIPPET_TEXT:
-
- #!/bin/bash
- CHARS="abcdefghijklmnopqrstuvwxyz0123456789_ .-,@:;()%\$!{}[]=*+#°§²³"
- FIRST_CHARS="abcdefghijklmnopqrstuvwxyz0123456789_"
- BASE_DIR="source"
- ((DIR_LEVELS=$RANDOM%5))
- ((DIR_COUNT=$RANDOM%50))
- ((FILES_PER_DIRECTORY=$RANDOM%50))
- export CHARS FIRST_CHARS DIR_LEVELS DIR_COUNT FILES_PER_DIRECTORY BASE_DIR
- randfirstchar() {
- local idx
- ((idx=$RANDOM%${#FIRST_CHARS}))
- echo "${FIRST_CHARS:$idx:1}"
- }
- randchar() {
- local idx
- ((idx=$RANDOM%${#CHARS}))
- echo "${CHARS:$idx:1}"
- }
- mk_token() {
- local length
- local token=""
- ((length=$RANDOM % 20 + 4))
- token=$(randfirstchar)
- for((i=1;i<=$length;i++));do
- token="$token$(randchar)"
- done
- echo "$token"
- }
- mk_content() {
- local dir_levels="$1"
- local files_per_directory="$2"
- local new_dir="$(mk_token)"
- local i
- if [ $dir_levels -gt 0 ] ;then
- mkdir "$new_dir"
- cd "$new_dir"
- mk_content $((dir_levels - 1)) $files_per_directory
- cd ..
- fi
- for ((i=1;i<=$files_per_directory;i++));do
- touch "$(mk_token)"
- done
- }
- main() {
- cd "$BASE_DIR"
- local a b c
- local current_dir
- for((a=1;a<$DIR_COUNT;a++));do
- mk_content $DIR_LEVELS $FILES_PER_DIRECTORY
- done
- }
- main
Quellcode
Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN