summaryrefslogtreecommitdiff
path: root/perms
blob: d38548beebecaa1924ea03c134c407a3b5338bb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env bash

if [[ $1 == "-v" ]]; then
    export verbose=1
    shift
fi
file="$1"
echo $(realpath "$file")

if [[ -n "$verbose" ]]; then
    perm=$(stat --printf "%a" "$file")
    declare -A permMap=( [0]="no perms" [1]="execute" [2]="write" [3]="write, execute"
                         [4]="read" [5]="read, execute" [6]="read, write" [7]="read, write, execute" )

    owner="${permMap[${perm:0:1}]}"
    group="${permMap[${perm:1:1}]}"
    other="other:\t\t\t${permMap[${perm:2:1}]}"
else
    owner=""
    group=""
    other=""
fi


stat --printf "octal: %a\nhuman: %A\nowner: %U (%u)\t$owner\ngroup: %G (%g)\t$group\n$other" "$file"