Using `find -perm` to find when a permission is not set

LinuxBashFind

Linux Problem Overview


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.

Linux Solutions


Solution 1 - Linux

Try:

find . ! -perm -g+r

Solution 2 - Linux

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

find . ! -readable

Solution 3 - Linux

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionUser1View Question on Stackoverflow
Solution 1 - LinuxjgrView Answer on Stackoverflow
Solution 2 - LinuxCharleyView Answer on Stackoverflow
Solution 3 - Linuxseenshee91View Answer on Stackoverflow