Monday, May 6, 2024
19
rated 0 times [  19] [ 0]  / answers: 1 / hits: 583593  / 3 Years ago, mon, june 21, 2021, 2:10:44

What is the command line that displays file informations (or properties), such as in GUI method Display properties in GNOME?



Display properties GNOME



I know that ls -l shows properties; but how to display the same informations?



For example, instead of



rw-rw-r--


we have such GUI rendering:



abdennour@estifeda: $wishedCmd myFile
.....
Permissions :
Owner Access: Read & write
Group Access :Read & Write
Others Access: Read only
.....


Screenshot of permissions dialogue


More From » command-line

 Answers
7

Something like



#!/bin/bash
print_perm() {
case "$1" in
0) printf "NO PERMISSIONS";;
1) printf "Execute only";;
2) printf "Write only";;
3) printf "Write & execute";;
4) printf "Read only";;
5) printf "Read & execute";;
6) printf "Read & write";;
7) printf "Read & write & execute";;
esac
}

[[ ! -e $1 ]] && echo "$0 <file or dir>" 2>&1 && exit 1

perm=$(stat -c%a "$1")
user=${perm:0:1}
group=${perm:1:1}
global=${perm:2:1}

echo "Permissions :"
printf " Owner Access: $(print_perm $user)
"
printf " Group Access: $(print_perm $group)
"
printf " Others Access: $(print_perm $global)
"


Output



# rwxr-x--- foo*
> ./abovescript foo
Permissions :
Owner Access: Read & write & execute
Group Access: Read & execute
Others Access: NO PERMISSIONS

[#29124] Tuesday, June 22, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
horicgly

Total Points: 36
Total Questions: 126
Total Answers: 104

Location: Iceland
Member since Thu, Dec 1, 2022
1 Year ago
;