#!/bin/bash # # shop - Show Permissions at all levels of a given path # # With `tree(1)` you start at a trunk and show all leaves that # originate from that trunk, optionally showing permissions. # `shop` starts at a leaf and shows the permissions back to a # trunk. # # CREATED: 2009-09-03 17:30 # MODIFIED: 2009-11-17 11:05 _NAME=$(basename $0) _VERSION=1.0 # DEFAULTS unset octal # use text mode instead of octal mode level=-1 # traverse all the way up to / trunk='/' # traverse all the way up to / pad=17 # padding for pathname usage() { cat < /dev/null elif [ $level -eq 0 ]; then break; fi done # display the permissions for each level while [ "$PWD" != "$start_dir" ]; do _shop "$PWD" popd &> /dev/null done _shop "$PWD" # leaf was a file, run _shop on this file as well if [ $file_arg ]; then _shop "${PWD}/$(basename -- "$arg")" else cd .. || return 1 fi # user passed multiple leafs, separate output for each leaf if [ $# -gt 1 ]; then echo fi shift arg="$1" done } declare -a args until [ -z "$1" ]; do case "$1" in -L|--level) level="$2" shift 2 ;; -o|--octal) octal=1 shift ;; -t|--trunk) trunk="$(readlink -f $2)" shift 2 ;; -p|--pad) pad="$2" shift 2 ;; -h|--help) usage exit ;; --version) echo "$_NAME v$_VERSION" exit ;; --) shift args=( "${args[@]}" "$@" ) break ;; -*) echo -e "$_NAME: unknown option: $1\n" usage exit ;; *) args[${#args[*]}]="$1" shift ;; esac done main "${args[@]}"