Using `find -perm` to find when a permission is not set
LinuxBashFindLinux 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.