Linux-查找命令理解

本文介绍了Linux系统中快速查找文件的两个命令:locate基于数据库的快速查找,适用于已知文件名的情况;find则通过遍历目录,提供多种参数如-name、-iname、-maxdepth、-mtime等进行精确查找,适合复杂查询条件。同时,文章还提到了find命令中根据文件类型、修改时间和权限等进行查找的功能。
摘要由CSDN通过智能技术生成

locate

快速查找所需要的文件或者目录,因此他并不会去搜索全部数据信息。

如:

[root@NIKE ~]# touch NIKE.txt
[root@NIKE ~]# locate NIKE.txt
[root@NIKE ~]# locate NIKE.txt
/root/NIKE.txt

find

查找速度较慢,对整个目录进行遍历,会占用很多系统资源。

-name 通过名字查找,不确定名字的时候用“*”配通符,如(*p.txt)(p*.txt)(*.txt)

[root@NIKE ~]# find / -name "nike.txt"
/root/nike.txt
[root@NIKE ~]# find / -name "*n.txt"
/root/nike.txt
/root/no.txt
(以下结果部分省略)

-iname 通过名字查找,添加“i”属性,不确定名字时的另一种方法查询。

[root@NIKE ~]# find / -iname "nike.txt"
/root/nike.txt
/root/no.txt
(以下结果部分省略)

-maxdepth 根据目录层数查询(不清楚文件在哪个目录可以用)

[root@NIKE ~]# find / -maxdepth 2 "nike.txt"
/root/nike.txt
[root@NIKE ~]# find / -maxdepth 5 "nike.txt"

-mtime 根据修改时间查询

[root@NIKE ~]# find / -mtime +1 
/root/nike.txt
/root/no.txt
(以下结果部分省略)
+为大于
-为小于

-type 根据类型查询文件

[root@NIKE ~]# find / -type f (普通文件)
[root@NIKE ~]# find / -type d (目录文件)
[root@NIKE ~]# find / -type l (链接文件)
[root@NIKE ~]# find / -type b (块设备文件)
[root@NIKE ~]# find / -type c (字符设备文件)
[root@NIKE ~]# find / -type s (套接字文件)
[root@NIKE ~]# find / -type p (管道文件)

-perm 根据权限查询文件(rwx)

[root@NIKE ~]# find / -prem  644 -ls
71426922 4 -rw-r--r-- 
58625189 4 -rw-r--r--
(结果部分省略)

-(user,group,nouser,nogroup)可以根据属组,属主查询

[root@NIKE ~]# find / -user f (普通文件)
[root@NIKE ~]# find / -group d (目录文件)
[root@NIKE ~]# find / -nouser l (链接文件)
[root@NIKE ~]# find / -nogroup b (块设备文件)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

妮可珍郝坎

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值