Table of Contents

BASH - Find - Find Files Based On their Permissions

The typical syntax to find files based on their permissions is:

find -perm mode

NOTE: The MODE can be either with numeric or octal permission (like 777, 666.. etc) or symbolic permission (like u=x, a=r+x).

The MODE can be specified in three different ways:

  • If we specify the mode without any prefixes, it will find files of exact permissions.
  • If we use “-“ prefix with mode, at least the files should have the given permission, not the exact permission.
  • If we use “/” prefix, either the owner, the group, or other should have permission to the file.

Find files based on numeric permissions

Find Files Based On their Numeric (octal) Permissions

Now let me run the following command:

find -perm 777

NOTE: This command will find the files with permission of exactly 777 in the current directory.


Using "-" prefix

find -perm -766

NOTE: This will find all files where the file owner has read/write/execute permissions, file group members have read/write permissions and everything else has also read/write permission.

  • Yes, it will display files which do have 766 permissions.
  • But this may also display some files which do not have exact 766 permissions.
    • This could include files with tighter permissions too.

Using "/" prefix

find -perm /222

NOTE: This will find files which are writable by somebody (either their owner, or their group, or anybody else).

find -perm /220

NOTE: This will find files which are writable by either their owner or their group.

  • That means the files do not have to be writable by both the owner and group to be matched; either will do.

But if you run the same command with “-” prefix, you will only see the files only which are writable by both owner and group.

find -perm -220

Find Files Based On their Permissions using symbolic notation

Symbolic notations is used such as u (for user), g (group), o (others).

NOTE:

  • The letter a can be used to represent all three of these categories.
  • The permissions can be specified using letters r (read), w (write), x (executable).

To find any file with group write permissions

find -perm -g=w

NOTE: You can use either “=” or “+” for symbolic notation.

  • It does not matter.

For example, the following two commands will do the same thing.

find -perm -g=w
find -perm -g+w

Find any file which are writable by the file owner

find -perm -u=w

Find any file which are writable by all (the file owner, group and everyone else)

find -perm -a=w

Find files which are writable by both their owner and their group

find -perm -g+w,u+w

NOTE: The above command is equivalent of find -perm -220 command.


Find files which are writable by either their owner or their group

find -perm /u+w,g+w

or,

find -perm /u=w,g=w

NOTE: These two commands do the same job as the find -perm /220 command.


Help

For more details, refer the man pages.

man find