I read man page for find
but it is not clear for me.
find -perm -mode
------>at least these bit(s) must be set for a file to match
For example: find -perm -754
finds 754,755,757,774,777
What about? find -perm /754
please explain to me by examples
It's basically the difference between all three bits (
-mode
) and any single bit (/mode
) permission (-perm
) subset test.find -perm -mode
:In this case the permission bits mentioned must be present for the file. For example, if you do
find -perm -666
and if a file has776
, it will be matched. Similarly666
,777
etc will be matched too, but665
won't be matched. In summary, the mentioned (three) bits must be a subset of the permission bits.find -perm /mode
:Here any one bit of subset would do. For example, if we do
find -perm /666
, and if a file has644
, the file will be matched because the user permission bit is6
, and we are looking for a single bit subset. Similarly,700
,060
,006
etc will be matched, but not e.g.444
, as no bit contains any subset of the required permission bits.The other answer correctly explains the
find -perm -mode
part. However, this answer corrects an incorrect claim about thefind -perm /mode
part.The first sentence is true, however, the part claiming
444
would not be matched is not.-perm /mode
matches if any permission bit matches, not a whole number.When passing /666, we are asking the
find
command to look for files that have any of the following bitsrw-rw-rw
(6 = 4+2 which means rw-). So it will match any file that is readable, or writable, or both by any type of owner (user, group or other). That means the only files that will not be matched are files with the following permissions:000
,001
,010
,011
,100
,101
,110
, and111
. Any other permission will be matched by-perm /666
as it would have either the read or write flags assigned to it.For more clarification, check the following example.
So the only thing it does not match are the files that have permissions not containing 2 or 4: i.e. all files that contain only 1 or 0:
maybe to clarify a bit:
given the following permissions
/
is an OR operation:return w&W || x&X|| y&Y || z&Z
i.e. return if file contains any permission (W-Z) that matches (at least) the searched permissions (w-z).
while
-
is an AND operation:return w&W && x&X && y&Y && z&Z
i.e. return if file contains all permissions (W-Z) match (at least) the searched permissions (w-z).
In both cases that can mean that W has set more than w bits (6 sets 2 and 4, but not 3 or 1)