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 }
Never been to CodeSnippets before?
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)
dirmodes (See related posts)
You need to create an account or log in to post comments to this site.
Related Posts
» newfolder contextual menu it... in shell osx mac bash unix folder directory menu automator contextual
» open or cd to the directory ... in shell osx mac bash unix file open cd directory shortcut
» ws - web search from the com... in shell osx mac search bash unix commandline web
» snippet in shell osx mac html bash unix commandline web download convert textutil
» Switching firewall settings ... in shell osx mac bash unix ipfw firewall ruleset switch
» Delete WebKit search fields in shell osx mac bash unix safari webkit
Snippets (source code soon to be available) developed by Peter Cooper and powered by Ruby On Rails