查找文件
根据预设的条件递归查找对应的文件
– find [目录] [条件1] [-a|-o] [条件2] ...
– 常用条件表示:
-type 类型(f文件、d目录、l快捷方式)
-name "文档名称"
-size +|-文件大小(k、M、G)
-user 用户名
[root@server0 ~]# find /boot/ -type f #文本文件
[root@server0 ~]# find /boot/ -type d #目录
[root@server0 ~]# find /boot/ -type l #快捷方式
[root@server0 ~]# ls -l /boot/grub/menu.lst
[root@server0 ~]# find /etc/ -name "passwd"
/etc/passwd
/etc/pam.d/passwd
[root@server0 ~]# find /etc/ -name "*tab"
[root@server0 ~]# find /etc/ -name "*tab*"
请查找/etc以 .conf 结尾(包含子目录)
[root@server0 ~]# find /etc -name "*.conf"
请查找/etc以 .conf 结尾(不包含子目录)
[root@server0 ~]# ls /etc/*.conf
[root@server0 ~]# touch /root/asd.txt
[root@server0 ~]# touch /root/asd2.txt
[root@server0 ~]# mkdir /root/asd1803
[root@server0 ~]# find /root/ -name "asd*"
[root@server0 ~]# find /root/ -name "asd*" -type f
[root@server0 ~]# find /root/ -name "asd*" -type d
-size +10M 按 文件大小查找
[root@server0 ~]# find /boot/ -size +10M
[root@server0 ~]# find /boot/ -size +300k
-user 用户 按用户 (不晓得用户名 白搭 虽然没影响)
[root@server0 ~]# find /home/ -user student
[root@server0 ~]# find / -user student
-group 组名 按组 (找出来的 是真的多。)
[root@server0 ~]# find /home/ -group student
使用find命令的 -exec 操作
– find .. .. -exec 处理命令 {} \;
– 优势:以 {} 代替每一个结果,逐个处理,遇 \; 结束
# find /boot/ -name "vm*"
# find /boot/ -name "vm*" -exec cp {} /opt \;
# ls /opt/
# find /boot/ -size +10M
# find /boot/ -size +10M -exec cp {} /opt \;
# ls /opt/