Originally Posted by Simon_zhu
I've been playing around with the -perm option of the find command, and I want to know what the difference is between the -perm -mode and -perm /mode
And if possible to give an example of each? I have tried both and they both seem to give the same result.
If you look in the manpage, it describes how the mode is being used:
All of the permission bits mode are set for the file. Symbolic
modes are accepted in this form, and this is usually the way in
which would want to use them. You must specify `u', `g' or `o'
if you use a symbolic mode. See the EXAMPLES section for some
Any of the permission bits mode are set for the file. Symbolic
modes are accepted in this form. You must specify `u', `g' or
`o' if you use a symbolic mode. See the EXAMPLES section for
some illustrative examples. If no permission bits in mode are
set, this test matches any file (the idea here is to be consis‐
tent with the behaviour of -perm -000).
This is no longer supported (and has been deprecated since
2005). Use -perm /mode instead.
And the examples section:
find / \( -perm -4000 -fprintf /root/suid.txt '%#m %u %p\n' \) , \
\( -size +100M -fprintf /root/big.txt '%-10s %p\n' \)
ANY setuid file...(the only bit set - all other bits, since they are 0, are ignored). If any other bits are set, then the mode of the file must match ALL of them.
The major difference between the three (-/ and no prefix) is "ALL set bits must match, ANY set bit must match, and exact match"
and more examples from the manpage:
find . -perm 664
Search for files which have read and write permission for their owner,
and group, but which other users can read but not write to. Files
which meet these criteria but have other permissions bits set (for
example if someone can execute the file) will not be matched.
find . -perm -664
Search for files which have read and write permission for their owner
and group, and which other users can read, without regard to the pres‐
ence of any extra permission bits (for example the executable bit).
This will match a file which has mode 0777, for example.
find . -perm /222
find . -perm -g+w,u+w
Both these commands do the same thing; search for files which are
writable by both their owner and their group.
find . -perm -444 -perm /222 ! -perm /111
find . -perm -a+r -perm /a+w ! -perm /a+x
These two commands both search for files that are readable for every‐
body ( -perm -444 or -perm -a+r), have at least one write bit set (
-perm /222 or -perm /a+w) but are not executable for anybody ( ! -perm
/111 and ! -perm /a+x respectively).