suid,find用法
Set UID
• 附加在所有者的 x 位上
– 所有者的权限标识会变为 s
– 适用于可执行文件,Set UID可以让使用者具有文件属主的身份及部分权限
– 传递所有者身份
[root@server0 ~]# cp /usr/bin/mkdir /usr/bin/xixidir
[root@server0 ~]# ls /usr/bin/xixidir
[root@server0 ~]# chmod u+s /usr/bin/xixidir
[root@server0 ~]# ls -l /usr/bin/xixidir
[root@server0 ~]# su - student
[student@server0 ~]$ /usr/bin/mkdir test01
[student@server0 ~]$ /usr/bin/xixidir test02
[student@server0 ~]$ ls -l
[student@server0 ~]$ exit
#####################################################
Sticky Bit
• 附加在其他人的 x 位上
– 其他人的权限标识会变为 t
– 适用于开放 w 权限的目录,可以阻止用户滥用 w 写入
权限(禁止操作别人的文档)
[root@server0 ~]# useradd harry
[root@server0 ~]# useradd natasha
[root@server0 ~]# mkdir /public
[root@server0 ~]# chmod ugo=rwx /public
[root@server0 ~]# ls -ld /public
[root@server0 ~]# chmod o+t /public
[root@server0 ~]# ls -ld /public
#####################################################
查找文件
• 根据预设的条件递归查找对应的文件
– find [目录] [条件1] [-a|-o] [条件2] ...
– 常用条件表示:
-type 类型(f文件、d目录、l快捷方式)
-name "文档名称"
-size +|-文件大小(k、M、G)
-user 用户名
[root@server0 ~]# find /boot/ -type l #查找是快捷方式
[root@server0 ~]# ls /boot/grub/menu.lst
[root@server0 ~]# ls -l /boot/grub/menu.lst
[root@server0 ~]# find /boot/ -type d #查找是目录
[root@server0 ~]# find /boot/ -type f #查找是文件
##################################################
[root@server0 ~]# find /etc/ -name "passwd"
显示/etc/目录下以.conf结尾?(不包含子目录)
[root@server0 ~]# ls /etc/*.conf
显示/etc/目录下以.conf结尾?(包含子目录)
[root@server0 ~]# find /etc/ -name "*.conf"
[root@server0 ~]# touch /root/nsd01.txt
[root@server0 ~]# touch /root/nsd02.txt
[root@server0 ~]# mkdir /root/nsd1804
[root@server0 ~]# find /root/ -name "nsd*"
[root@server0 ~]# find /root/ -name "nsd*" -a -type f
[root@server0 ~]# find /root/ -name "nsd*" -type f
[root@server0 ~]# find /root/ -name "nsd*" -type d
##################################################
[root@server0 ~]# find /boot/ -size +10M
[root@server0 ~]# find /boot/ -size +300k
• 使用find命令的 -exec 操作
– find .. .. -exec 处理命令 {} \;
– 优势:以 {} 代替每一个结果,逐个处理,遇 \; 结束
# find /boot/ -size +300k -exec cp -r {} /opt \;
# ls /opt
# find /root -name "nsd*" -type f -exec cp -r {} /opt \;
# ls /opt
查找属于某个用户
[root@server0 ~]# find /home/ -user student
[root@server0 ~]# find / -user student
[root@server0 ~]# mkdir /root/findfiles
[root@server0 ~]# find / -user student -type f
[root@server0 ~]# find / -user student -type f -exec cp {} /root/findfiles/ \;
[root@server0 ~]# ls -A /root/findfiles/
• 根据名称查找,忽略大小写
– -iname
[root@server0 ~]# find /etc/ -name "PASSWD"
[root@server0 ~]# find /etc/ -iname "PASSWD"
• 根据账号名称或所属组
– -group
[root@server0 ~]# find /home/ -group student
• 限制目录查找的深度(最大层数)
– -maxdepth
[root@server0 ~]# find /etc/ -name "passwd"
[root@server0 ~]# find /etc/ -maxdepth 1 -name "passwd"
[root@server0 ~]# find /etc/ -maxdepth 2 -name "passwd"
[root@server0 ~]# find /etc/ -maxdepth 1 -name "*.conf"
[root@server0 ~]# find /etc/ -maxdepth 2 -name "*.conf"
• 根据文件修改时间(过去时间)
• -mtime
[root@server0 ~]# find /var/log -mtime +90 #过去时间90天之前
[root@server0 ~]# find /var/log -mtime -90 #过去时间90天之内

浙公网安备 33010602011771号