Answer the question
In order to leave comments, you need to log in
How to determine file permissions for a specific user?
You need to display for the test user the access rights to the test.txt file in the rwx format.
Can you do something more elegant?
I got it like this:
user="test";
file1="test.txt";
#USER
res=`stat -c %U $file1`;
if ; then
tmp=`stat -c %A $file1 |cut -c2-4`;
echo $user ":" $tmp;
continue;
fi
#GROUP
grp=`stat -c %G $file1`;
res=`getent group $grp | awk -F: '{print $4}' | grep -E $user'(,|$)'`
if ; then
tmp=`stat -c %A $file1 |cut -c5-7`;
echo $user ":" $tmp;
continue;
fi
#OTHER
tmp=`stat -c %A $file1 |cut -c8-10`;
echo $user ":" $tmp;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question