创建脚本
创建一个名为 myresearch
的脚本
该脚本放置在 /usr/bin
下
该脚本用来查找 /usr
下所有小于 10m
且具有修改 SGID
权限的文件,将这些文件名称放置于
/root/myfiles
文件中
创建脚本
创建一个名为 newsearch
的脚本
该脚本放置在 /usr/bin
下
该脚本用来查找 /usr
下所有大于
30k
,但是小于 50k
且具有 SUID
权限的文件,将这些文件名列表保存在 /root/newfiles
文件中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| [root@node1 ~]# find /usr -size -10M -perm /2000 | xargs ls -lh -rwx--s--x. 1 root slocate 47K Aug 12 2018 /usr/bin/locate -rwxr-sr-x. 1 root tty 21K Dec 17 2019 /usr/bin/write -r-xr-sr-x. 1 root ssh_keys 619K Jan 8 2020 /usr/libexec/openssh/ssh-keysign -rwx--s--x. 1 root utmp 13K Aug 12 2018 /usr/libexec/utempter/utempter [root@node1 ~]# vim /usr/bin/myresearch #!/bin/bash find /usr -size -10M -perm /2000 > /root/myfiles [root@node1 ~]# chmod +x /usr/bin/myresearch [root@node1 ~]# /usr/bin/myresearch [root@node1 ~]# cat /root/myfiles /usr/bin/write /usr/bin/locate /usr/libexec/utempter/utempter /usr/libexec/openssh/ssh-keysign
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| [root@node1 ~]# find /usr -size +30k -size -50k -perm /4000 | xargs ls -lh -rws--x--x. 1 root root 33K Dec 17 2019 /usr/bin/chfn -rwsr-xr-x. 1 root root 33K Dec 13 2019 /usr/bin/passwd -rwsr-xr-x. 1 root root 33K Dec 17 2019 /usr/bin/umount -rwsr-x---. 1 root cockpit-wsinstance 46K Mar 12 2020 /usr/libexec/cockpit-session -rwsr-xr-x. 1 root root 37K Dec 19 2019 /usr/sbin/unix_chkpwd -rws--x--x. 1 root root 47K Nov 20 2018 /usr/sbin/userhelper [root@node1 ~]# vim /usr/bin/newsearch #!/bin/bash find /usr -size +30k -size -50k -perm /4000 > /root/newfiles [root@node1 ~]# chmod +x /usr/bin/newsearch [root@node1 ~]# /usr/bin/newsearch [root@node1 ~]# cat /root/newfiles /usr/bin/umount /usr/bin/passwd /usr/bin/chfn /usr/sbin/unix_chkpwd /usr/sbin/userhelper /usr/libexec/cockpit-session
|
-perm
选项用于查找具有特定权限集的文件。权限可以描述为八进制值,包含代表读取、写入和执行的
4、2 和 1 的某些组合。权限前面可以加上 / 或 - 符号。
前面带有 /
的数字权限将匹配文件的用户、组、其他人权限集中的至少一位。权限为
r--r--r-- 的文件并不匹配 /222,权限为 rw-r--r-- 的文件才匹配。权限前带有
-
符号表示该位的所有三个实例都必须存在,因此前面的两个示例都不匹配,但诸如
rw-rw-rw- 的对象则匹配。
与 / 或 - 一起使用时,0
值类似于通配符,因此其表示至少无任何内容的权限。