I have been trying for hours to figure out the command syntax to find files that meet any of these criteria but I cannot seem to figure it out.

  • user does not have read
  • user does not have write
  • group does not have read
  • group does not have write
  • other does not have read
  • other has write
  • other has execute

I started with this but this dosen't find all the expected files. For example it doesn't find files where other has read but also has execute.

find /path -type f \( ! -perm /u=rw,g=rw -or ! -perm /o=r \) -print
  • IMHO the problem is not the syntax but the logic: -perm /u=rw,g=rw gets you all the files where any of these flags is set, so ! -perm /u=rw,g=rw` get you the files where none of these flags is set. So maybe you want ! -perm /u=rw,g=rw` (ie; not {all the flags set} which is the same as {at least one flag unset}. – xenoid Jul 27 '17 at 12:29
  • Do you have a typo? Looks like you typed the same thing the last time... – IMTheNachoMan Jul 27 '17 at 13:07
  • Indeed. Meant -perm -u=rw,g=rw. Thanks. – xenoid Jul 27 '17 at 15:16

Short answer

 find ./ -type f ! \( -perm -u=rw -and -perm -g=rw -and -perm -o=r -and ! -perm /o=wx \)

Long answer

As it seems easier to specify what we want (x has y permission) in find, let's try to conjugate the expression: we can see that a file that should not match has all of these conditions verified:

  • user has read and write
  • group has read and write
  • other has read
  • other does not have (write or execute)

So now we have more has than before (5 vs 2). I wrote the command that find the files that you do not want:

find ./ -type f -perm -u=rw -and -perm -g=rw -and -perm -o=r -and ! -perm /o=wx

To understand it you must mind the fact that - means all of the permissions and / means any of the permissions.

Then I conjugated it with ! and parenthesis to get the command at the top of this answer.


Let's create files that verify only one of each of these criteria:

mkdir demo && cd demo
touch     a b c d e f g
chmod 777 a b c d e f g
chmod u-r a
chmod u-w   b
chmod g-r     c
chmod g-w       d
chmod o-r         e
chmod o-w a b c d e g
chmod o-x a b c d e f

Then let's create all the files that should not match: We have freedoms on

  • user execution rights
  • group execution rights

Which gives exactly 2^2 = 4 types of full permissions that should not match. Let's create 4 files with these criteria:

touch     h i j k
chmod 664 h i j k
chmod u+x h i
chmod g+x h   j

The provided command should match files a to e but not files h to k. Of course this test is not exhaustive because there are 256 types of permissions to test.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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