Linux Find: by Permission

tanut aran
Nov 8, 2020

--

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
  • Prefix - = AND
  • Prefix / = OR

Negate the result

Unfortunately, to find non-executable file is not very straightforward.

The symbolic - minus sign is NOT working

$ find . -perm -u-x,g-x,o-x --> NOT WORKING

To invert the result you needs ! or -not flag prefix the -perm

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!

--

--

tanut aran
tanut aran

Written by tanut aran

Co-founder and Coder at work !

No responses yet