73

I want to find the non-readable files in my directory (eg the files with g-r). So I tried this:

find . -perm -g-r

It shows me all of the files?? So I tried this:

find . -perm -g+r

And it showed me only the readable files. It appears that -perm -g-r matches all files. I'm using CentOS 5.5. Am I doing something wrong? It doesn't look like -perm -g-r does anything useful.

User1
  • 39,458
  • 69
  • 187
  • 265
  • 1
    I believe that the `-` prefix to the permissions parameter means match files with "at least" these permissions. So it matches files that are not group-readable _as well as_ files that are group-readable, because group-readable files have a group permission that is considered "greater than" `g-r` – osullic Jun 13 '19 at 11:26

4 Answers4

105

Try:

find . ! -perm -g+r

jgr
  • 3,914
  • 2
  • 24
  • 28
  • 3
    That worked! I'm still mystified by `-perm -g-r` not working, but oh well. – User1 Dec 07 '10 at 23:23
  • It's an obvious extension to find files that are not executable, too. Thanks! – Walter Nissen Mar 22 '11 at 21:44
  • 1
    What if I want to limit my search to files and not directories, and want a `-maxdepth` of 2? I mean, how do I negate the perms while asserting the other things? EDIT: Nevermind. You can negate any option with !. It didn't seem to be working at first, but it really was. I did `find -maxdepth 2 ! -perm -g+r -type d` and found directories to a depth of 2 that did not have group read permission. – Buttle Butkus Nov 25 '12 at 09:03
  • I think the `-perm` option does not support `g-r` as in `chmod g-r ` – jervtub May 15 '18 at 11:41
26

If you want to find files that are non-readable by you, you could use

find . ! -readable
Charley
  • 578
  • 3
  • 13
0

on my Debian I need to escape the negation "exclamation mark" so in your case it would be

find . \! -perm -g+r -ls

using numbers is also an option. This was my quest:

find . \! -perm /444 

to see what really happens use:

find . \! -perm /444 -exec ls -la {} \;
na8ur
  • 1
  • 1
-3

You were able to see all files when you executed the below instruction, because you were executing it as root.

find . -perm -g-r

Try executing as a normal user.

Mia Clarke
  • 8,134
  • 3
  • 49
  • 62
seenshee91
  • 11
  • 1