@@ -43,7 +43,19 @@ MINSIZE=2000
43
43
# the containing folder for the random tree
44
44
BASENAME=randtree
45
45
# extensions for the random files
46
- EXTS=(md log json js php jpg png html css)
46
+ EXTS=(md log json js php jpg png html css txt)
47
+ # ##########################################################
48
+ # optional, will increment a count for each EXTS used and
49
+ # show it at the end
50
+ INVEN=true
51
+ # this will use the EXTS array to build an array of counters
52
+ if [ " $INVEN " = true ]; then
53
+ declare -A ext_inven
54
+ for ext in " ${EXTS[@]} "
55
+ do
56
+ ext_inven+=([" $ext " ]=0)
57
+ done
58
+ fi
47
59
# ##########################################################
48
60
# "mutable" echoing
49
61
SILENT=true
@@ -68,13 +80,20 @@ mkranfiles() {
68
80
num_EXTS=${# EXTS[*]}
69
81
for i in $( seq 1 $NUMRFILES )
70
82
do
71
- # Random file name
72
- fname=` mktemp -u XXXXXXX." ${EXTS[$((RANDOM%num_EXTS))]} " `
83
+ # Random file extension
84
+ fext=" ${EXTS[$((RANDOM%num_EXTS))]} "
85
+ # Random file name and extension
86
+ fname=` mktemp -u XXXXXXX." $fext " `
73
87
# Random file size within a specific range
74
88
fsize=$(( $MINSIZE + $RANDOM % $MAXSIZE ))
75
89
# Add random content to files using allowed chars
76
90
cat /dev/urandom | tr -dc A-Z-a-z-0-9-" " | head -c${1:- $fsize } > $fname
77
91
mutecho $fname
92
+ if [ " $INVEN " = true ]; then
93
+ tmp=${ext_inven[$fext]}
94
+ tmp=$(( tmp+= 1 ))
95
+ ext_inven+=([$fext ]=$tmp )
96
+ fi
78
97
done
79
98
}
80
99
# make a filled random folder tree
111
130
done
112
131
echo " Finshed in $PWD "
113
132
133
+ # show how many of each file extension we created
134
+ if [ " $INVEN " = true ]; then
135
+ echo
136
+ echo " File Extension Counts:"
137
+ for x in " ${! ext_inven[@]} " ; do printf " [%s] = %s\n" " $x " " ${ext_inven[$x]} " ; done
138
+ fi
0 commit comments