Linux-find command understanding

locate

Quickly find the files or directories you need, so he doesn't search all the data.

like:

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

find

The search speed is slow, and traversing the entire directory will occupy a lot of system resources.

-name Search by name, use "*" wildcard when you are not sure about the name, such as (*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 Search by name, add "i" attribute, another way to query when you are not sure about the name.

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

-maxdepth queries based on the number of directory levels (it is not clear in which directory the file can be used)

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

-mtime Query based on modification time

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

-type Query files based on 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 Query files based on permissions (rwx)

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

-(user,group,nouser,nogroup) can be queried based on the group and owner

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

Guess you like

Origin blog.csdn.net/nikezhenhaokan/article/details/130278649