bash:find:find_files_based_on_their_permissions
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
bash:find:find_files_based_on_their_permissions [2022/06/13 08:37] – created peter | bash:find:find_files_based_on_their_permissions [2022/06/13 08:59] (current) – peter | ||
---|---|---|---|
Line 7: | Line 7: | ||
</ | </ | ||
- | The MODE can be either with numeric or octal permission (like 777, 666.. etc) or symbolic permission (like u=x, a=r+x). | + | <WRAP info> |
+ | **NOTE: | ||
- | We can specify the MODE in three different ways as listed below. | + | The MODE can be specified |
* If we specify the mode without any prefixes, it will find files of exact permissions. | * 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 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. | + | * 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. | + | </ |
---- | ---- | ||
Line 29: | Line 30: | ||
</ | </ | ||
- | This command will find the files with permission of exactly 777 in the current directory. | + | <WRAP info> |
+ | **NOTE: | ||
+ | </ | ||
- | Now, let us use “-” prefix | + | ---- |
+ | |||
+ | ===== Using " | ||
<code bash> | <code bash> | ||
Line 37: | Line 42: | ||
</ | </ | ||
- | The above command displays two files. | + | <WRAP info> |
+ | **NOTE: | ||
- | We have set 766 permission to file2, but this command displays two files, why? | + | * Yes, it will display files which do have 766 permissions. |
- | Because, here we have used “-” prefix”. | + | * But this may also display some files which do not have exact 766 permissions. |
+ | * This could include files with tighter permissions too. | ||
- | 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 | + | ===== Using "/" |
<code bash> | <code bash> | ||
Line 53: | Line 60: | ||
</ | </ | ||
- | The above command | + | <WRAP info> |
+ | **NOTE: | ||
+ | </ | ||
<code bash> | <code bash> | ||
Line 59: | Line 69: | ||
</ | </ | ||
- | This command | + | <WRAP info> |
+ | **NOTE: | ||
- | But if you run the same command with “-” prefix, you will only see the files only which are writable by both owner and 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. | ||
<code bash> | <code bash> | ||
find -perm -220 | find -perm -220 | ||
</ | </ | ||
- | |||
- | The following screenshot will show you the difference between these two prefixes. | ||
---- | ---- | ||
Line 73: | Line 86: | ||
===== Find Files Based On their Permissions using symbolic notation ===== | ===== Find Files Based On their Permissions using symbolic notation ===== | ||
- | In the following examples, we use symbolic | + | Symbolic |
- | For instance, | + | <WRAP info> |
+ | **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 ==== | ||
<code bash> | <code bash> | ||
Line 81: | Line 104: | ||
</ | </ | ||
- | 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 | + | <WRAP info> |
+ | **NOTE: | ||
+ | |||
+ | * It does not matter. | ||
+ | |||
+ | </ | ||
+ | |||
+ | For example, the following two commands will do the same thing. | ||
<code bash> | <code bash> | ||
Line 88: | Line 118: | ||
</ | </ | ||
- | To find any file which are writable by the file owner, run: | + | ---- |
+ | |||
+ | ==== Find any file which are writable by the file owner ==== | ||
<code bash> | <code bash> | ||
Line 94: | Line 126: | ||
</ | </ | ||
- | To find any file which are writable by all (the file owner, group and everyone else), run: | + | ---- |
+ | |||
+ | ==== Find any file which are writable by all (the file owner, group and everyone else) ==== | ||
<code bash> | <code bash> | ||
Line 100: | Line 134: | ||
</ | </ | ||
- | To find files which are writable by both their owner and their group, use this command: | + | ---- |
+ | |||
+ | ==== Find files which are writable by both their owner and their group ==== | ||
<code bash> | <code bash> | ||
Line 106: | Line 142: | ||
</ | </ | ||
- | The above command is equivalent of “find -perm -220” command. | + | <WRAP info> |
+ | **NOTE: | ||
+ | </ | ||
- | To find files which are writable by either their owner or their group, run: | + | |
+ | ---- | ||
+ | |||
+ | ==== Find files which are writable by either their owner or their group ==== | ||
<code bash> | <code bash> | ||
Line 120: | Line 161: | ||
</ | </ | ||
- | These two commands | + | <WRAP info> |
+ | **NOTE: | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Help ===== | ||
For more details, refer the man pages. | For more details, refer the man pages. | ||
Line 128: | Line 175: | ||
</ | </ | ||
- | Also, check the man pages alternatives to learn more simplified examples of any Linux command. | + | |
bash/find/find_files_based_on_their_permissions.1655109453.txt.gz · Last modified: 2022/06/13 08:37 by peter