# Integration: walk a directory tree with recursion and globbing. mkdir -p t/a/b t/c t/.hid touch t/f1 t/a/f2 t/a/b/f3 t/a/b/f4 t/c/f5 t/.hid/f6 't/sp ace' walk() { # dir depth for e in "$1"/* "$1"/.[!.]*; do [ -e "$e" ] || continue printf '%*s%s%s\n' $(($2 * 2)) '' "${e##*/}" "$( [ -d "$e" ] && echo /)" [ -d "$e" ] && walk "$e" $(($2 + 1)) done } walk t 0 count() { n=0 for e in "$1"/*; do if [ -d "$e" ]; then count "$e" n=$((n + $?)) elif [ -e "$e" ]; then n=$((n + 1)) fi done return $n } count t; echo "files (no dot dirs): $?"