I need to get Access rights in
more human readable
format for file or folder with a symbolic notation like this u=rwx,g=srwx,o-rwx
(possibly sticky bits)
- Using
stat --format '%a'
, I obtain a result with format2770
, octal format - Using
stat --format '%A'
, I obtain a result with formatdrwxrws---
, human readable
I need a command to obtain a format like u=rwx,g=srwx,o-rwx
(compatible with chmod symbolic modes
)
[u|g|o]
: foruser
/group
/other
ora
for all[=]
: for rights granted[rwxst]
: list of rights granted no order importance[-rwx]
:for right revoked (if no right granted)
I have tried this ( But it doesn't handle all cases, specialy sticky bits) :
stat --format '%A' temp |
sed -E 's/^.(...)(...)(...)/u=\1,g=\2,o=\3/g' | # split by triplet
sed 's/=---/-rwx/g' | # revoker grants
sed 's/rws/srwx/g' | # setgid with x ...
sed 's/--S/s/g' | # setgid without x ...
sed ... nead more transormation... # manage sticky bit setuid setgid
I search a more elegant way.
example input ==> output
drwxrws---
==>u=rwx,g=srwx,o-rwx
(begin by d ==> directory)drwxrwxrwx
==>u=rwx,g=rwx,o=rwx
orugo=rwx
ora=rwx
-r-xrw-r--
==>u=rx,g=rw,o=r
(begin by - ==> regular file)-rwx--S---
==>u=rwx,g=s,o-rwx
(S in uppercase)------s--t
==>u=-srwx,g=sx,o=xt
(Stickybit)
input format ==> like commands stat
or ls -al
output format==> must be compatible with chmod
This complete version seems works, but I'm sure we can simplify it, ( ie without multiple sed )
stat --format '%A' a |
sed -E 's/^.(...)(...)(...)/u=\1,g=\2,o=\3/g' | # split by triplet
sed -E 's/s/xs/g' | # setgid ou setuid with x ...
sed -E 's/t/xt/g' | # sticky bit with x ...
sed -E 's/S/s/g' | # setgid ou setuid without x ...
sed -E 's/T/t/g' | # sticky bit alone
sed -E 's/-//g' | # remove -
sed -E 's/=(,|$)/-rwx\1/g' # revoker grants