E
E
elBroom2016-05-25 12:18:14
linux
elBroom, 2016-05-25 12:18:14

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

1 answer(s)
D
Dmitry Tallmange, 2016-05-25
@p00h

stat -c %a /path/to/file
In general man stat,stat --help

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question