linux文件搜索命令 find

linux文件搜索命令

find

语法:find [搜索范围] [搜索条件]
  • -name 根据文件名进行查找
  • -iname 不区分大小写
  通配符 * 代表任意长度任意量
  		? 代表一个字符
eg: 搜索文件名为init的文件
	[root@localhost ~]# find /etc -name init
	/etc/selinux/targeted/active/modules/100/init
	/etc/sysconfig/init
搜索文件名包含init的文件 find /etc -name *init*
搜索以init开头的文件    find /etc -name init*
搜索文件名为initxxx 的文件 find /etc -name init???
[root@localhost ~]# 
  • -size根据文件大小搜索
    • +表示大于
    • -表示小于
eg: find / -size +204800 //搜索根目录下文件大小大于100MB的文件
	[root@localhost ~]# find / -size +204800
	/usr/lib/locale/locale-archive
	/proc/kcore
	find: ‘/proc/52972/task/52972/fd/6’: No such file or directory
	find: ‘/proc/52972/task/52972/fdinfo/6’: No such file or directory
	find: ‘/proc/52972/fd/5’: No such file or directory
	find: ‘/proc/52972/fdinfo/5’: No such file or directory
	/sys/devices/pci0000:00/0000:00:0f.0/resource1_wc
	/sys/devices/pci0000:00/0000:00:0f.0/resource1
//	在linux中文件大小以数据块为单位一个数据块为0.5KB
	即100MB为102400KB为204800个数据块
  • -user -group 根据所有者,所属组查询
eg: //根据所有者查询
	[root@localhost ~]# find /root -user qq
	/root/h1
	//根据所属组查询
	[root@localhost ~]# find /root -group baidu
	/root/h1/h5
  • -amin(access minutes) ,-cmin(change minutes) , -mmin(modify minutes)
    根据访问时间,属性修改时间,内容修改时间查询 -表示小于,+表示大于
eg ://所搜访问时间小于20minutes的文件
	[root@localhost ~]# find /root -amin -20
	/root/v1
	/root/h1
	/root/h1/h5
//搜索在100分钟内的修改属性文件
	[root@localhost ~]# find /root -cmin -100
	/root/h1
	/root/h1/h5
//搜索当前目录中在5分钟修改内容的文件
	[root@localhost ~]# find . -mmin -5
	./k1
  • -type 搜索文件内行为…的文件(f表示文件,l表示连接, d表示目录)
eg: 查找当前目录下文件类型为目录的文件
	[root@localhost ~]# find . -type d
	.
	./v1
	./h1
	./h1/h5
  • -inum 根据I节点查找
eg:	//查找当前目录下i节点为某值得文件
	[root@localhost ~]# ls -i
	524297 h1  524303 k1  524300 v1
	[root@localhost ~]# find . -inum 524297
	./h1
  • -exec/-ok 查询后对文件再进行操作
eg: //查询当前文件下名字为h1的文件夹并列举出其中内容
	[root@localhost ~]# find . -name h1 -exec ls -l {} \;
	total 4
	dr--r--r--. 2 root baidu 4096 Jan 23 12:35 h5
//二者不同点在于ok需要进行确认,如下
	[root@localhost ~]# find . -name h1 -ok ls -l {} \;
	< ls ... ./h1 > ? y
	total 4
	dr--r--r--. 2 root baidu 4096 Jan 23 12:35 h5
  • -o,a(or,and)当使用多条件时使用
eg://查找根目录下文件大小大于50M小于100M的文件
	[root@localhost ~]# find / -size +102400 -a -size -204800
	/boot/initramfs-0-rescue-263ae32223a74cddba13d15ff867da6c.img
//查找/etc目录下以init开头或者以init结尾的的文件
	[root@localhost ~]# find /etc -name *init -o -name  init*
	/etc/selinux/targeted/active/modules/100/init
	/etc/selinux/targeted/contexts/initrc_context
	/etc/inittab
	/etc/rc.d/init.d
	/etc/sysconfig/init
	/etc/sysconfig/network-scripts/init.ipv6-global
	/etc/init.d
	/etc/security/namespace.init
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值