Linux之find命令

Linux之find相关命令

一、find命令

1、what?

  • 查询指定目录文件的命令

2、how?

  • find [路径] [选项] [表达式]
1、参数

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-orx5pfZ6-1642657575829)(D:\王康波\markdown资源\image-20220120094531901.png)]

2、type分类
f	#普通文件 
d	#目录 
l	#链接 
b	#块设备 
C	#字符设备 
s	#套接字 
p	#管道
3、size分类
b   #block块 (不添加单位默认就是block块: 512字节) 
w   #2字节 
c   #字节 
K   #K = 1024c 
M   #兆 = 1024K 
G   #G = 1024M

3、use

1、按名字查找
-name 与 -iname :后者不区分大小写

find /etc -name 'wkb.txt'   # /etc/wkb.txt
find /etc -iname 'wkb.txt'	# /etc/wkb.txt
						  #	/etc/WKb.txt
find /etc -iname '*.txt'    # 模糊匹配
2、按文件到大小
-size 
find /etc -size +5M			# 查询大于5M的文件
find /etc -size 5M			# 查询等于5M的文件
find /etc -size -5M			# 查询小于5M的文件
find /etc -size 5M ls  		 # 查询5M文件后的查看操作 
3、指定查找目录的深度
-maxdepth
find /etc -maxdepth 5 -name 'wkb.txt' # 查询最大深度5的文件
4、按照时间查找
find /etc -mtime +3   		# 查询修改时间超过三天的
find /etc -mtime 3			# 查询修改时间等于三天的
find /etc -mtime -3			# 查询修改时间小于三天的
5、查看一个文件的元数据
  • stat [文件名]
6、按属组查找
find /root -user alpha       			  # 属主是alpha
find /root -group alpha2	     		  # 属组是alpha2
find /root -user alpha -group alpha2       # 属主和属组
find /root -user alpha -a -group -alpha2   # 属主和属组 (不加 -a 默认 -a )
find /root -user salpha -o -group -alpha2  # 属主或者属组满足一个就可以
7、按文件类型查找
find /root -type f          #普通文件
find /root -type d          #目录
find /root -type l          #链接
find /root -type c          #字符设备
find /root -type b          #块设备
find /root -type s          #套接字
find /root -type p          #管道文件
8、按文件权限查找
find /root -perm -777 -print     #不加 "-print" 默认就是 "-print"
find /root -perm -777 -ls 
find /root -perm -777 -ls
9、找到文件后续处理

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-KnYwLq3K-1642657575833)(../markdown资源/image-20220120113109688.png)]

find /root -name "wkb*" -print  #默认就是 "-print"
find /root -name "wkb*" -ls
find /root -name "wkb*" -delete #找到删除
find /root -name "wkb*" -exec rm -rf {} \;  #找到删除

find /root -name "wkb*" -ok cp -rvf {} /tmp \;  #交互式,每次都会提醒:"y/n"
find /root -name "wkb*" -exec cp -rvf {} /tmp \;  #非交互式,不会提醒
10、find 与 xargs 配合使用
  • xargs的作用:让不支持管道的命令也可以使用管道内的内容
find /root -name "wkb*" | xargs rm -rvf   #删除管道里的内容
find /root -name "wkb*" | xargs -I {} cp -rf {} /tmp
find /root -name "wkb*" | xargs -I {} mv {} /tmp
find /root -name "wkb*" | xargs -I {} chmod 777 {} #修改找到的文件的权限等级
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值