Linux Find: by Permission
There are time we would like to find the files that is ‘readable’ or ‘executable’. So this command will help in such situation.
According to User
Below command is based on the current user.
find . -readable
find . -writable
find . -executable
For example, ‘readable’ is according to your current user.
If you login with root or other user this will be different.
According to File
Sample scenario is when to find any file that is at least executable by someone.
$ find . -perm /u=x,g=x,o=x
Negate the result
Unfortunately, to find non-executable file is not very straightforward.
- minus sign is NOT working
$ find . -perm -u-x,g-x,o-x --> NOT WORKING
To invert the result you needs
-not flag prefix the
find . ! -perm -a=x,g=x,o=x -printf "%M %p\n"
To expand the result:
! -a=x,g=x,o=x --> a!=x OR g!=x OR o!=x
! /a=x,g=x,o=x --> a!=x AND g!=x AND o!=x
There we go.
Hope this helps!