ubuntu:find:find_files_based_on_their_permissions
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
ubuntu:find:find_files_based_on_their_permissions [2020/07/15 09:30] – external edit 127.0.0.1 | ubuntu:find:find_files_based_on_their_permissions [2022/06/13 08:37] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Ubuntu - Find - Find Files Based On their Permissions ====== | ||
- | |||
- | The typical syntax to find files based on their permissions is: | ||
- | |||
- | <code bash> | ||
- | find -perm mode | ||
- | </ | ||
- | |||
- | The MODE can be either with numeric or octal permission (like 777, 666.. etc) or symbolic permission (like u=x, a=r+x). | ||
- | |||
- | We can specify the MODE in three different ways as listed below. | ||
- | |||
- | * 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. | ||
- | |||
- | Allow me to explain with some examples, so you can understand better. | ||
- | |||
- | ---- | ||
- | |||
- | ===== Find files based on numeric permissions ===== | ||
- | |||
- | Find Files Based On their Numeric (octal) Permissions | ||
- | |||
- | Now let me run the following command: | ||
- | |||
- | <code bash> | ||
- | find -perm 777 | ||
- | </ | ||
- | |||
- | This command will find the files with permission of exactly 777 in the current directory. | ||
- | |||
- | Now, let us use “-” prefix and see what happens. | ||
- | |||
- | <code bash> | ||
- | find -perm -766 | ||
- | </ | ||
- | |||
- | The above command displays two files. | ||
- | |||
- | We have set 766 permission to file2, but this command displays two files, why? | ||
- | |||
- | Because, here we have used “-” prefix”. | ||
- | |||
- | In our case, file1 and file2 have met this criteria. In other words, the files need not to have exact 766 permission. | ||
- | |||
- | ---- | ||
- | |||
- | Next, we will use “/” prefix and see what happens. | ||
- | |||
- | <code bash> | ||
- | find -perm /222 | ||
- | </ | ||
- | |||
- | The above command will find files which are writable by somebody (either their owner, or their group, or anybody else). Here is another example. | ||
- | |||
- | <code bash> | ||
- | find -perm /220 | ||
- | </ | ||
- | |||
- | This command will find files which are writable by either their owner or their group. | ||
- | |||
- | But if you run the same command with “-” prefix, you will only see the files only which are writable by both owner and group. | ||
- | |||
- | <code bash> | ||
- | find -perm -220 | ||
- | </ | ||
- | |||
- | The following screenshot will show you the difference between these two prefixes. | ||
- | |||
- | ---- | ||
- | |||
- | ===== Find Files Based On their Permissions using symbolic notation ===== | ||
- | |||
- | In the following examples, we use symbolic notations such as u ( for user), g (group), o (others). We can also use the letter a to represent all three of these categories. The permissions can be specified using letters r (read), w (write), x (executable). | ||
- | |||
- | For instance, to find any file with group write permission, run: | ||
- | |||
- | <code bash> | ||
- | find -perm -g=w | ||
- | </ | ||
- | |||
- | As you see in the above example, file1 and file2 have group write permission. Please note that you can use either “=” or “+” for symbolic notation. It doesn’t matter. For example, the following two commands will do the same thing. | ||
- | |||
- | <code bash> | ||
- | find -perm -g=w | ||
- | find -perm -g+w | ||
- | </ | ||
- | |||
- | To find any file which are writable by the file owner, run: | ||
- | |||
- | <code bash> | ||
- | find -perm -u=w | ||
- | </ | ||
- | |||
- | To find any file which are writable by all (the file owner, group and everyone else), run: | ||
- | |||
- | <code bash> | ||
- | find -perm -a=w | ||
- | </ | ||
- | |||
- | To find files which are writable by both their owner and their group, use this command: | ||
- | |||
- | <code bash> | ||
- | find -perm -g+w,u+w | ||
- | </ | ||
- | |||
- | The above command is equivalent of “find -perm -220” command. | ||
- | |||
- | To find files which are writable by either their owner or their group, run: | ||
- | |||
- | <code bash> | ||
- | find -perm /u+w,g+w | ||
- | </ | ||
- | |||
- | or, | ||
- | |||
- | <code bash> | ||
- | find -perm /u=w,g=w | ||
- | </ | ||
- | |||
- | These two commands does the same job as “find -perm /220” command. | ||
- | |||
- | For more details, refer the man pages. | ||
- | |||
- | <code bash> | ||
- | man find | ||
- | </ | ||
- | |||
- | Also, check the man pages alternatives to learn more simplified examples of any Linux command. | ||
ubuntu/find/find_files_based_on_their_permissions.1594805433.txt.gz · Last modified: 2020/07/15 09:30 by 127.0.0.1