Linux-文件查找

# 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 参数传递

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值