#!/bin/bash export PATH=/bin:/sbin:/usr/bin:/usr/sbin if [ "$TERM" == "xterm" ]; then color=y elif [ "$TERM" == "xterm-color" ]; then color=y elif [ "$TERM" == "linux" ]; then color=y elif [ "$TERM" == "vt100" ]; then color=y elif [ "$TERM" == "rxvt" ]; then color=y else color=n fi if [ "$UID" == "0" ]; then root=y else root=n username=`whoami` fi if [ "$color" == "y" ]; then C1="\033[0;36m" C2="\033[1;36m" C3="\033[0m" else C1="\033[0m" C2="\033[1;39m" C3="\033[0m" fi ab_user=0 ab_group=0 ab_world=0 absolute=0 sticky=0 suid=0 sgid=0 if [ -z $1 ];then echo "Format: $0 (file|directory)" exit 1 elif [ ! -e $1 ];then echo "Please supply an existing file/directory" exit 1 fi tmp=`ls -ld $1 |awk '{print $1}'` user=`ls -ld $1 |awk '{print $3}'` group=`ls -ld $1|awk '{print $4}'` file=`ls -ld $1 |awk '{print $9}'` link=`ls -ld $1 |awk '{print $11}'` type="Filename" for x in 0 1 2 3 4 5 6 7 8 9 ; do perm[$x]=${tmp:$x:1} done if [ "${perm[0]}" == "d" ]; then type="Directory" elif [ "${perm[0]}" == "l" ]; then type="Link" fi symbolic="User: $C1${perm[1]}${perm[2]}${perm[3]}$C2" symbolic="$symbolic Group: $C1${perm[4]}${perm[5]}${perm[6]}$C2" symbolic="$symbolic World: $C1${perm[7]}${perm[8]}${perm[9]}" if [ "${perm[3]}" == "s" ]; then suid="4" ab_user=1 elif [ "${perm[3]}" == "S" ]; then suid="4" fi if [ "${perm[6]}" == "s" ]; then sgid="2" ab_group=1 elif [ "${perm[6]}" == "S" ]; then sgid="2" fi if [ "${perm[9]}" == "t" ]; then sticky="1" ab_world=1 elif [ "${perm[9]}" == "T" ]; then sticky="1" fi if [ "${perm[1]}" == "r" ]; then ab_user=$(($ab_user + 4)) fi if [ "${perm[2]}" == "w" ]; then ab_user=$(($ab_user + 2)) fi if [ "${perm[3]}" == "x" ]; then ab_user=$(($ab_user + 1)) fi if [ "${perm[4]}" == "r" ]; then ab_group=$(($ab_group + 4)) fi if [ "${perm[5]}" == "w" ]; then ab_group=$(($ab_group + 2)) fi if [ "${perm[6]}" == "x" ]; then ab_group=$(($ab_group + 1)) fi if [ "${perm[7]}" == "r" ]; then ab_world=$(($ab_world + 4)) fi if [ "${perm[8]}" == "w" ]; then ab_world=$(($ab_world + 2)) fi if [ "${perm[9]}" == "x" ]; then ab_world=$(($ab_world + 1)) fi absolute=$(($suid + $sgid + $sticky)) if [ "$absolute" == "0" ]; then absolute="" fi absolute=$absolute$ab_user$ab_group$ab_world echo echo -en "$C1 $type: $C2$file" if [ "$type" == "Link" ]; then echo -e "$C1 Linked To$C2 $link" else echo -en "\n" fi echo -e "$C1 Owner: $C2$user$C1 Group: $C2$group" echo -e "$C1 Permissions: $C2${perm[*]}" echo -e "$C1 Absolute: $C2$absolute" echo -e "$C1 Symbolic: $C2$symbolic$C3"