roa*_*chs 1 unix gnu-findutils find-util
我正在寻找所有setuid/setgid文件.当我不使用时-exec,它按预期工作:
# find /usr/bin -type f -perm -4000 -o -perm -2000
/usr/bin/wall
/usr/bin/ksu
/usr/bin/chage
/usr/bin/chfn
/usr/bin/chsh
/usr/bin/fusermount
/usr/bin/passwd
/usr/bin/write
/usr/bin/su
/usr/bin/umount
/usr/bin/gpasswd
/usr/bin/newgrp
/usr/bin/mount
/usr/bin/pkexec
/usr/bin/crontab
/usr/bin/cgclassify
/usr/bin/cgexec
/usr/bin/ssh-agent
/usr/bin/Xorg
/usr/bin/at
/usr/bin/sudo
/usr/bin/locate
/usr/bin/staprun
Run Code Online (Sandbox Code Playgroud)
当我使用时-exec,我只得到一部分结果:
# find /usr/bin -type f -perm -4000 -o -perm -2000 -exec ls -l {} \;
-r-xr-sr-x. 1 root tty 15344 Jan 27 2014 /usr/bin/wall
-rwxr-sr-x. 1 root tty 19536 Aug 21 2015 /usr/bin/write
-rwxr-sr-x. 1 root cgred 15624 Sep 21 2014 /usr/bin/cgclassify
-rwxr-sr-x. 1 root cgred 15584 Sep 21 2014 /usr/bin/cgexec
---x--s--x. 1 root nobody 306304 Sep 24 2015 /usr/bin/ssh-agent
-rwx--s--x. 1 root slocate 40504 Jan 26 2014 /usr/bin/locate
Run Code Online (Sandbox Code Playgroud)
为什么?
你只是-exec在右边使用-o.因此,它被解析如下:
# What's actually happening
find /usr/bin '(' -type f -perm -4000 ')' -o '(' -perm -2000 -exec ls -l {} \; ')'
Run Code Online (Sandbox Code Playgroud)
显然,这不是你想要的.
要使其适用于条件的两侧,请添加一些用于分组的parens:
# What you want to happen
find /usr/bin -type f '(' -perm -4000 -o -perm -2000 ')' -exec ls -l {} +
Run Code Online (Sandbox Code Playgroud)
原因是如果您未指定显式操作,则将a find 假定-print为默认操作.当您自己添加操作时,它会关闭默认值,因此只有您明确指定操作的项才会获得一个.
也就是说:
# These commands are all equivalent:
find /usr/bin -type f -perm -4000 -o -perm -2000
find /usr/bin '(' -type f -perm -4000 -o -perm -2000 ')' -print
find /usr/bin '(' '(' -type f -perm -4000 ')' -o '(' -perm -2000 ')' ')' -print
Run Code Online (Sandbox Code Playgroud)
请注意最后一个,它暴露了默认行为中的警告:您可能希望将-type f其应用于两侧-o,但如果没有显式分组,则会将其放在左侧,就像显式-exec或print放在右侧一样.
这个故事的道德:当-o在find中使用时,要明确你的分组,除非你非常确定默认行为是你想要的.
| 归档时间: |
|
| 查看次数: |
88 次 |
| 最近记录: |