# find 路径 条件 跟条件相关的操作符 [-exec 动作]
过滤 grep find查找
find /home/ -name "test*" | xargs -i cp {} /tmp/ #找到之后删除处理xargs 参数传递
拷贝 ls 路径 | xargs -i cp -rvr {} / ---要拷贝的路径
按文件名
从根开始找文件
[root@qfedu.com ~]# find / -name “file2” #从根开始找文件
/root/file2
/var/tmp/file2
[root@qfedu.com ~]# find /etc -name "ifcfg-ens33" #以名字的方式查找
[root@qfedu.com ~]# find /etc -iname "Ifcfg-ens33" #-i忽略大小写
按文件大小-size
[root@qfedu.com ~]# find /etc -size +5M #大于5M
[root@qfedu.com ~]# find /etc -size 5M #等于5M
[root@qfedu.com ~]# find /etc -size -5M #小于5M
[root@qfedu.com ~]# find / -size +3M -a -size -5M #查找/下面大于3M而且小于5M的文件
-a:and
[root@qfedu.com ~]# find / -size -1M -o -size +80M #查找/下面小于1M或者大于80M的文件
-o:or
[root@qfedu.com ~]# find / -size -3M -a -name "*.txt" #查找/ 下面小于3M而且名字是.txt的文件
按时间
按时间找(atime,mtime,ctime)
-atime = access访问时间
-mtime = modify改变时间 内容修改时间会改变
-ctime = change修改时间 属性修改时间会改变
-amin #分钟
-mmin
-cmin
[root@qfedu.com ~]# find /opt -mtime +5 #修改时间5天之前
[root@qfedu.com ~]# find /opt -atime +1 #访问时间1天之前
[root@qfedu.com ~]# find . -mtime -2 #修改时间2天之内
[root@qfedu.com ~]# find . -amin +1 #访问时间在1分钟之前
[root@qfedu.com ~]# find /opt -amin -4 #访问时间在4分钟之内
[root@qfedu.com ~]# find /opt -mmin -2 #修改时间在2分钟之内
按文件类型
[root@qfedu.com ~]# find /dev -type f #f普通文件
[root@qfedu.com ~]# find / -type f -size -1M -o -name "*.txt"
[root@qfedu.com ~]# find /dev -type d #d目录
[root@qfedu.com ~]# find /etc/ -type d -name "*.conf.d"
[root@qfedu.com ~]# find /etc -type l #l链接
[root@qfedu.com ~]# find /dev -type b #b块设备
[root@qfedu.com ~]# find /dev/ -type b -name "sd*"
按文件权限
[root@qfedu.com ~]# find . -perm 644 #.是当前目录 精确查找644
[root@qfedu.com ~]# find /usr/bin -perm -4000 #包含set uid
[root@qfedu.com ~]# find /usr/bin -perm -2000 #包含set gid
[root@qfedu.com ~]# find /usr/bin -perm -1000 #包含sticky
找到后处理的动作 ACTIONS
[root@qfedu.com ~]# find /etc -name "ifcfg*" -exec cp -rf {} /tmp \; #exec命令对之前查找出来的文件做进一步操作----- 查找带ifcfg开头的文件复制到tmp下
[root@qfedu.com ~]# touch /home/test{1..20}.txt
[root@qfedu.com ~]# find /home/ -name test* -exec rm -rf {} \; #{}为前面查找到的内容,\; 格式
find 使用xargs
[root@qfedu.com ~]# touch /home/test{1..20}.txt
[root@qfedu.com ~]# # find /home/ -name "test*" | xargs -i cp {} /tmp/ #找到之后删除处理xargs 参数传递