Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm searching for a command that essentially would do the following: check which rights a user has on a file/dir (including ACL) and return it.

E.g. say you have the following directory:

-rw-r--r-- 1 user1 group1 [snip] file1
-rw-rw-r-- 1 user2 group1 [snip] file2
drwxrwx--- 1 user2 group2 [snip] dir1

Then the commands & output should be (if user1 is a member of only group1):

rights user1 file1 => r-- or 4
rights user1 file2 => rw- or 6
rights user1 dir1 => --- or 0

Is there such a command available or which tools/commands can't be used to construct a script which would do it?

share|improve this question

I elaborate the following bash code

# Use: $0 user files

sudo -u "$user" bash -c 'for f; do
      [[ -r "$f" ]] && printf 'r' || printf '-'
      [[ -w "$f" ]] && printf 'w' || printf '-'
      [[ -x "$f" ]] && printf 'x' || printf '-'
      printf " %s\\n" "$f"
  done' _ "$@"

This should automatically take into account acl, if available, but the drawback is the use of sudo (or alternatively su) to become $user.

share|improve this answer
I had thought of this, but doesn't this create an enormous security leak? The executing user would need sudo rights... – dtech Sep 3 '11 at 17:21
I realised that shortly after commenting, see my edited comment – dtech Sep 3 '11 at 17:28
What if calling user do not have access to those files parent directories? It cannot in any way determine access rights for another user. – enzotib Sep 3 '11 at 17:33
If the calling user doesn't have access it should return false or an error (I'd like to use it as an additional layer of access control, the service can't even serve anything it doesn't have access to) – dtech Sep 3 '11 at 17:39
@dtech: I do not have a clear idea on how to do, so I hope someone else get in with a better answer. – enzotib Sep 3 '11 at 17:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.