8.1 File Lookup Local;find use

Source: Internet
Author: User

File Lookup:

Find eligible files on the file system.

File Lookup: Locate, find

Non-real-time lookup (Database lookup): Locate
Real-time Find: Find

Locate

1 querying the pre-built file index database on the system/var/lib/mlocate/mlocate.db
2 builds that rely on pre-built indexed indexes are automatically made when the system is idle (recurring tasks), and the administrator manually updates the database (UpdateDB)
3 The index build process needs to traverse the entire root filesystem, consuming resources very

Working characteristics:

? Fast Search Speed
? Fuzzy Lookup
? Non-real-time lookup

? Search for the full path of the file, not just the filename
? may only search directories where the user has read and Execute permissions

Locate command

Locate KEYWORD

Useful options
 -i 不区分大小写的搜索  -n N 只列举前N个匹配项目  -r 使用正则表达式
Example

Search for a file with "conf" in the name or path
Locate conf
Use Regex to search for files ending with ". conf"
Locate-r '. conf$ '

Find

Real-time Find tool to complete file lookups by traversing a specified path

Working characteristics:

Find speed slightly slower
Exact search
Real-time Search
may only search directories where the user has read and Execute permissions

Find [OPTION] ... [Find Path] [Search Criteria] [Handling Action]
Find path: Specify a specific target path; defaults to the current directory
Search criteria: Specifies the criteria for finding criteria, such as file name, size, type, permissions, etc., by default to find all files under the specified path
Handling actions: Perform actions on eligible files, output to screen by default

Find criteria

1 refers to the search hierarchy
-maxdepth level maximum Search directory depth, specified directory 1th
-mindepth level minimum Search directory depth
2 working with files in the directory before processing the directory
-depth

3 Search by file name and Inode:

-name "file name": Support using Glob *,?, [], [^]
-iname "file name": Letter case insensitive
-inum n Search by inode number
-samefile name the same inode number file
-links n files with number of links n
-regex "pattern": matches the entire file path with pattern, not the file name

4 Depending on the genus, the genus Group looks for:

-user USERNAME: Find files that belong to the specified user (UID)
-group GRPNAME: Finding files that belong to a specified group (GID)
-uid UserID: Find the file that belongs to the specified UID number
-gid GroupID: Finding files with a specified GID number for the genus Group
-nouser: Finding files that are not owned by the master
-nogroup: Finding files that are not owned by a group

5 Find by File type:
-type TYPE: ? f: 普通文件  ? d: 目录文件  ? l: 符号链接文件  ? s:套接字文件  ? b: 块设备文件  ? c: 字符设备文件  ? p: 管道文件

Empty file or directory
-empty
Find/app-type D-empty

Find condition Combination criteria:

With:-A
Or:-O
Non:-not,!

De Morgan Law:

(not a) or (not B) = Non (A and B)
(Non-a) and (not B) = Non (A or B)

Example:

! A-a! B =! (A-o B)
! A-o! B =! (A-a B)

Find Example:

Find-name Snow.png
Find-iname Snow.png
Find/-name ".txt"
Find/var–name "
log*"
Find-user Joe-group Joe
Find-user Joe-not-group Joe
Find-user Joe-o-user Jane
Find-not (-user joe-o-user Jane)
Find/-user joe-o-uid 500

Find files in the/tmp directory where the owner is not root and the file name does not start with F
Find/tmp (-not-user root-a-not-name ' F')-ls
Find/tmp-not (-user root-o-name ' F
') – ls

Exclude Directory

Find all other. conf suffix files under/etc/, except for the/ETC/SANE.D directory
Find/etc-path '/ETC/SANE.D '-a–prune-o-name ". conf"
Find all the. conf suffix files under/etc/, except/ETC/SANE.D and/etc/fonts two directories
Find/etc (-path "/ETC/SANE.D"-o-path "/etc/fonts")-a-prune-o-Name "
. conf

Depending on the file size, look for:

-size [+|-] #UNIT common units: K, M, G,c (byte)
#UNIT: (#-1, #] such as: 6k (5k,6k]
-#UNIT: [0,#-1] such as: -6k = [0,5k]
+ #UNIT: (#,∞) such as: +6k (6k,∞)

Find/-size +10000c #查找出大于10000000字节的文件 (c: Bytes, W: double word, K:KB,M:MB,G:GB)
Find/-size-1000k #查找出小于1000KB的文件

Based on timestamp: "Days" as the unit

1-atime find the last n24-hour files accessed in the system
Find/-atime-2 # finds files accessed in the last 48 hours of the system
2-mtime
Find/-mtime-1 #查找在系统中最后24小时里修改过的文件
3-ctime find the last n
24-hour changed state file in the system

In "Minutes" units

1-amin find the last n minutes of files accessed in the system
Find/-amin-10 # finds files accessed in the last 10 minutes of the system
2-mmin
Find/-mmin-5 # finds files that have been modified in the last 5 minutes of the system
3-cmin find the last n minutes of the system changed state of the file

Search by permissions:

-perm [/|-]mode
MODE: Exact permission match
/mode: The permission of any class (U,g,o) object can be a match, or a relationship, + from the CENTOS7 start elimination
-mode: Each class of objects must have the specified permission, and the relationship

0 indicates no concern
Find-perm 755 matches a file with a permission pattern of exactly 755
As long as any person has write permission, Find-perm +222 will match
find-perm-222 matches only when everyone has permission to write
FIND-PERM-002 matches only if other people (other) have write permissions

Handling actions

-ls: Similar to performing a "ls-l" command on a found file
-delete: Delete the found file
-fls file: Long format information for all files found is saved to the specified files
-ok COMMAND {} \; Executes commands specified by command on each file found, and interactively asks the user to confirm each file before executing the command
-exec COMMAND {} \; Executes commands specified by command on each file found
When you use the OK or EXEC option, you must end with \; where {} represents all the results found by the Find command. As a result, there are sometimes too many command errors, or the command does not support the standard input through the pipe pass parameter.

8.1 File Lookup Local;find use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.