--find of File Finder Tool

Source: Internet
Author: User

Introduction: Linux All Files, in the Linux system if we need to find the required files, in addition to step by step to find, there is another way is to use the Linux Find File Tool command, allows us to quickly locate the files we need. So we have to learn the document search tool



First, we need to understand the difference between text search and file lookup

Text Search: Filter and match the contents of a text file according to the pattern and character specified by the user. Commonly used tools are "grep", "Egrep", "Fgrep"

File lookup: According to the various attributes of the file to match the corresponding file. Common tools are "find", "locate"



Second, the tool for file lookup differences

First, we need to understand the 2 method of file lookup.

1, real-time lookup: is the traversal of all files to match the conditions. Common commands: "Find"

Advantages: It can find and match accurately, and can find the latest files in real time.

Cons: Slow speed

2, non-real-time lookup: is based on the index database to find. Common commands: "Locate"

Advantages: Fast Search speed

Cons: ① non-accurate lookups, but also belong to Fuzzy Lookup

② must rely on the index database to be able, and is very time-consuming and resource-intensive when building indexes

Tip: The creation of an index database is updated when the system is idle and uses daily tasks, so the latest files cannot be found in real time. If you want to update the index database immediately, you can execute the command: updatedb



Third, find usage

Find [option] ... [Find Path] [Search Criteria] [Handling Action]

Default values for each parameter:

          • Find path: Default to Current path

          • Find condition: defaults to all files under the specified path

          • Handling actions: Default to display on screen

1. Find the path

1.1. Absolute path

[Email protected] ~]# find/tmp/test "*p*"

1.2. Relative path

[[email protected] tmp]# find/test "*p*"

2. Search Conditions

2.1.-name "Specify file name"

Note: Support for using globbing (wildcard character) characters

*: Any character of any length

?: any single character

[]: Any single character within the specified range

[^]: Any single character outside the specified range

[[email protected] tmp]# find/etc/-name "p*[0-9]*" means finding all files with "P" in the/etc/path and containing "number"

2.2.-iname "Specify file name": The case is not case-sensitive when it is found, and the default is casing-sensitive.

[Email protected] tmp]# find/etc/-iname "p*"

2.3.-user USERNAME: Search by file Owner

2.4,-group GROUPNAME: Search According to the genus Group of files to find

[Email protected] tmp]# find/home/-user user1

2.5,-uid UID: Search based on the owner of the file UID lookup

2.6.-gid GID: Find the GID based on the genus Group of the file

[Email protected] tmp]# find/home/-gid 600

2.7.-nouser: Find all files that are not owned by the owner

2.8.-nogroup: Find all files that are not owned by group

[[email protected] tmp]# Find/-nouser

2.9.-type Type: Search by file type

-F: Normal file

-D: Catalog file

-L: Symbolic link

-B: Block device

-C: Character device

-S: Socket file

-P: Named pipes

[Email protected] tmp]# find/etc/-type d-name "p*[0-9]*"

2.10,-size [+ |-] #UNIT: Based on file size to find

Unit: Represents the units. Common Unit; k,m,g

#: Represents a number

+: Represents a greater than

-: Represents a less than

650) this.width=650; "src=" Http://www.178linux.com/ueditor/php/upload/image/20150704/1435973445678872.png "title= "1435973445678872.png" alt= "find-size principle. png" width= "540" height= "204" style= "width:540px;height:204px;"/>

Example: With # = 9, UNIT = k

650) this.width=650; "src=" Http://www.178linux.com/ueditor/php/upload/image/20150704/1435973466564549.png "title= "1435973466564549.png" alt= "Test Find-size.png" width= "545" height= "401" style= "width:545px;height:401px;"/>

2.11,-perm [+ |-] MODE: Search by file permissions

MODE: Represents the user's permissions on the file, i.e. R (4), W (2), X (1)

Mode: Both the representation and the mode permission are precisely matched

+mode: The permissions on behalf of any class of users as long as it contains any one of its specified permissions to satisfy

-mode: Each class of user-specified permissions must be included, and is fully inclusive

650) this.width=650; "src=" Http://www.178linux.com/ueditor/php/upload/image/20150704/1435975095497087.png "title= "1435975095497087.png" alt= "Find-perm.png" width= "546" height= "333" style= "width:546px;height:333px;"/>

2.12, based on time stamp lookup

2.12.1, in "Days" as the unit

-atime [+ |-] #: Find based on access time

-mtime [+ |-] #: Find based on modified time

-ctime [+ |-] #: Find based on state change time

2.12.2, with "minutes" as the unit
-amin [+ |-] #: Find based on access time

-mmin [+ |-] #: Find based on modified time

-cmin [+ |-] #: Find based on state change time

650) this.width=650; "src=" Http://www.178linux.com/ueditor/php/upload/image/20150704/1435975589771116.png "title= "1435975589771116.png" alt= "find-atime principle. png" width= "554" height= "207" style= "WIDTH:554PX;HEIGHT:207PX;"/>

Example: Use Atime with # for 4

650) this.width=650; "src=" Http://www.178linux.com/ueditor/php/upload/image/20150704/1435975763138954.png "title= "1435975763138954.png" alt= "find atime exercises. png" width= "553" height= "156" style= "width:553px;height:156px;"/>

The meaning of the representative:

+4: Represents a file that was accessed more than or equal to 5 days ago

-4: Represents a file that was accessed less than or equal to 4 days ago

4: Represents 4 to 5 files accessed this day


2.13, according to the combination of conditions to find

means to perform a logical operation in a conditional statement statement

With:-A means must be met at the same time (the default value is-A, so-a can not be filled)

Or:-o means that one can be satisfied

Non:-not \! Refers to the condition to reverse

650) this.width=650; "src=" Http://www.178linux.com/ueditor/php/upload/image/20150704/1435977488102074.png "title= "1435977488102074.png" alt= "find combination. png" width= "580" height= "294" style= "width:580px;height:294px;"/>

Tip: The last example of the above example can also be used in the following way

[[email protected] test1]# Find/-not \ (-iname "*r*"-o-group tuser602 \)

3. Handling Actions

3.1,-print: Default processing action, display in the screen

3.2,-ls: equivalent to Ls-l (note: There will be a problem when using the combination condition)

3.3.-exec: Run command to execute a command on the found file

-exec command{} \; (note: \; Indicates that the end {} indicates that the file itself is referenced)

[[email protected] test1]# Find/-perm-001-exec chmod o-x {} \; Change all file permissions to 001 for o-x [[email protected] test1]# find./-perm +200-a-type f-a-not-name "* *"-exec mv {} {}.t  XT \; Add a. txt suffix to all files that do not have a suffix under the current path

3.4.-ok: Using Interactive execution commands

-ok COMMAND {} \;

Tip: Find all eligible files at once and pass them along to the commands specified later in-exec or-ok; however, some commands cannot accept too long arguments: so you should use another method

Find | Xargs COMMAND means to find a handle to a

[Email protected] test1]# find/tmp-name core-type f-print | Xargs/bin/rm-f



Iv. Summary

Use format for Find

Find [Find path] [find condition] [processing action]

Find path: Absolute path, relative path

Search conditions:-name,-iname,-user,-group,-uid,-gid,-nouser,-nogroup,-size,-perm

Search by timestamp:-mtime,-ctime, Atime,-amin,-mmin,-cmin

Search by combination condition:-A,-O,-not,!

Handling actions:-print,-ls,-exec,-ok






This article is from the "Crab Learn Linux" blog, please be sure to keep this source http://windchasereric.blog.51cto.com/5419433/1670812

--find of File Finder Tool

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.