Tools Find File
Tools Find File
locate: Non-real-time file finder
Query depends on the prior construction index database: /varlib/mlocatr/mlocate.db
index database is manually created and implemented by updatedb command to create updated, but for a more resource-consuming system, the proposed system idle
work characteristics locate in:
- Find faster, because the index database has been constructed in advance
- Fuzzy Lookup
- Non-real-time search, according to the database lookup, recently created files are typically not updated into the database
- Search the full path of the file
- You may only search for a user with permission to read and implement the current directory
Related options
locate -i 不区分大小写
-n 指定显示前几个
-r 使用正则表达式
示例: locate conf 搜索名称或路径中带有conf的文件
locate -r ‘\.conf$’ 搜索以.conf结尾的文件
find: Find a real-time tool
To find the path to the file specified by scanning
work characteristics:
- Find a bit slower
- Exact Match
- Find real-time
-
You may only search for a user with read and execute permissions to the directory
Syntax: find / path - Options - processing operation
path defaults to the current path is located
Find related options:
-
Find accordance with the conditions
find /root -user li 查找属主为li的文件 -group li 查找属组为li的文件 -uid 11 查找属主ID为11的文件 -gid 11 查找属组ID为11的文件 -nouser 查找没有属主的文件 -nogroup 查找没有属组的文件
-
Search by file type
find /root -type f 查找文件类型为f,即普通文件的文件 同上b:块设备文件 c:字符设备文件 d:目录文件 l:符号链接文件 s:套接字文件 p:管道文件 -empty 空文件或目录 示例: find /root -type d -empty 查找root下空的目录文件
-
Search by file size:
Supported by: k, m, gfind /root -size n 搜索大小为n的文件(实际搜索大小为n-1至n大小的文件) -n 搜索0至n-1大小的文件 +n 搜索大于n的文件 示例:find /root -size 100m 搜索root下99m到100m的文件
-
Search by timestamp:
find /root atime n 搜索n+1至n天间被读取过的文件 以天文单位 -n +n ctime n 搜索n天至n-1天元数据发生过更改的文件 -n +n mtine n 搜索n天至n-1天内容发生过更改的文件 -n +n 同上 amin n 以分钟为单位 cmin n mmin n
-
Search by permission:
find /root -perm 761 精确匹配 属主拥有7或属组拥有6或其他拥有1即匹配 -perm /761 模糊匹配 属主拥有7中任何一项或属组拥有6中任何一项或其他拥有1的权限及匹配 -perm -761 超·精确匹配 必须属主拥有7权限,同时属组拥有6权限,同时其他拥有1权限才匹配
-
Other search options;
-maxdepth n 指定搜索最大深度为n -mindepth n 指定搜索最小深度为n -depth 先处理目录内文件,在处理目录 -name 按文件名称搜索 支持通配符 -inum 按inode编号搜索 -samefile data 搜索与data相同inode号的文件 -links n 搜索链接数为n的文件
With multiple search criteria can be: in combination with -a or -o or -not
-a 与
-o 或
-not 非 或选项前加!
示例 :find /root -name file -o -user root
find /root -name file -a -user root
find /root -name file -not -user root
Processing related actions:
find /root -name data -ls 类似ls -l命令,显示额外信息
-delte 删除
-fls /xx/ 将搜索到的文件长格式信息保存在xx文件中
-ok 命令 {}/; 也可以接-ok,后面直接跟常用命令,结尾格式要求必须为{}/; {}引用前面搜索到文件的绝对路径 每个文件执行前都会要求用户交互式确认
-exec 命令 {}/; 同-ok上 非交互式
find the front of the processing operation is to search all the files back to a one-time transfer processing commands, some commands may not handle too many parameters, transmission need to use xargs
xargs Usage: Parameter | xargs processing operation
example
find -type f -name “*.txt” -print0 | xargs -0 rm
xargs transmission default separator is a space or carriage return, file name may have spaces as a named lead to conflict, this time used -print0 | xargs -0 specify delimiters for the NUL, NUL here is empty, a corresponding ascii decimal 0 code NUL