Linux-查找命令理解

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 (块设备文件)

猜你喜欢

转载自blog.csdn.net/nikezhenhaokan/article/details/130278649