dirmodes
function dirmodes() { declare dir user group mods declare -a ar ret declare -i size i n dir="$@" if [[ ! -e "$dir" ]]; then printf "%s\n" "Directory (or file) does not exist: $dir"; return 1; fi dir=${dir%/} # remove a trailing slash character "/" if necessary OIFS="$IFS" export IFS=$'\n' i=-1 while [[ -n "$dir" ]]; do i=$[i+1] user="$(/usr/bin/stat -f "%Su" "$dir")" group="$(/usr/bin/stat -f "%Sg" "$dir")" mods="$(/usr/bin/stat -f "%p" "$dir")" mods="${mods: -4}" #mods="$(/usr/bin/stat -f "%p" "$dir" | /usr/bin/grep -Eo "[[:digit:]]{4}$")" ar[$i]="$(printf "%-35s %-50s\n" $user:$group:$mods $dir)" dir="$(/usr/bin/dirname "$dir")" if [[ "$dir" == '/' ]]; then i=$[i+1] ar[$i]="$(printf "%-35s %-50s\n" $user:$group:$mods $dir)" dir="" fi done # get number of array elements size=$(/bin/expr ${#ar[@]} - 1 ) n=-1 for (( i=$size; i>=0; i-- )); do # reverse the array n=$[n+1] ret[$n]=${ar[$i]} printf "%s\n" "$(printf -- "${ar[$i]}" | tr -d '\r\n')" done export IFS="$OIFS" return 0 }