Find the Linux File Finder tool (Detailed)

Source: Internet
Author: User

Find detailed

A. What is the Find command?

Real-time Lookup tool that iterates through all the files in the specified directory to complete the lookup.

Two. Job features of Find:

Real-time Search

Find and support a wide range of search criteria

Find speed slightly slower

Three. Use of find:

Find [options][Find path] [find condition] [handle action]

(1) Find path : Specify the starting path of the specific search target, default to the current directory;

(2) Search criteria: The specified search criteria, according to the file name, size, type, affiliation, permissions and other standards.

Search by file name:

-name ' filename ': Exact Match of file name;

Support for GLOB-style wildcard characters: *,?, [], [^]

-iname ' filename ': file name matching is not case-sensitive;

-regex PATTERN: File name matching based on regular expression;

Search by Owner:-user USERNAME

Search by Genus:-group

Search by UID:-uid UID

Search by GID:-gid GID

Find files that are not owned by the master:-nouser

Find files without a group:-nogroup

Find by file type:-type F: Normal file

D: Catalog file

L: Symbolic Link file

B: Block device files

C: Character device file

P: Pipeline File

S: Socket file

Find by File Size:

-size [+|-] #UNIT

#UNIT: (#-1, #)

-#UNIT: [0,#-1]

+ #UNIT: (#, OO)

Common Unit:k, M, G

Example: Find/etc-size 10k, look for/etc more than 9k less than or equal to 10k files;

find/etc-size-10k, find files less than or equal to 9k under/etc;

Find/etc-size +10k, find files larger than 10k in/etc.


Combination condition:-A: and

-O: Or

-not: Non-

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

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

Find by file timestamp:

in "Days", the unit is 24 hours.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7D/44/wKioL1bkFc_AdofQAAAV-QCVtdM271.png "title=" Timeline 2.png "width=" 550 "height=" 153 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:550px;height:153px; "alt=" WKIOL1BKFC _adofqaaav-qcvtdm271.png "/>

The far right of the graph is the current time, and the farther left represents the earlier time axis;

3: The document representing 3-4 that day;

-3: Indicates a file that is less than or equal to 3 days;

+ 3: Represents a file that is greater than or equal to 4 days ago.

In "Days" as the unit:

-atime

-mtime

-ctime

In "Minutes" units:

-amin

-mmin

-cmin

-newer File:file for an existing file, list the file names that are newer than files.

Search by permissions:

-perm[/|-] Mode

Mode: Exact permission match

/mode: Any one (r,w,x) of the permissions of any class of users (U,g,o) satisfies the condition, and there is a "or" relationship between 9-bit permissions.

-mode: Every bit (r,w,x) in the permissions of each class of user (U,g,o) meets the criteria at the same time, and there is a "and" relationship between the 9-bit permissions.

(3) handling actions: Actions for files that match the search criteria, such as deletions, outputs, etc., by default output to standard output.

-print: Output to standard output, default action;

-ls: Similar to the "ls-l" command for the found file, the output file details;

-delete: Delete the found file;

-fls/path/to/somefile: Saves the long format information of all files found to the specified file;

-ok COMMAND {} \; : Executes commands for each file that is found, and each operation is confirmed by the user;

-exec COMMAND {} \; : Executes commands for each file that is found;

Note: When find passes the file path found to the following command, it is the first time to find out all eligible file paths and pass them to the following commands at once, but some commands cannot accept too long arguments, and command execution will fail; The following command mode can circumvent this problem:

Find | Xargs COMMAND

Four, practice operation

1. Find the main root of the/var directory, and belong to all files or directories of mail;

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7D/46/wKiom1bkGF6DSQJRAAAVCgS9_DI499.png "title=" Owner is the root group is group.png "width=" "height=" "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:700px;height:50px; "alt=" Wkiom1bkgf6dsqjraaavcgs9_di499.png "/>

2. Find all files or directories that do not belong to root, bin or hadoop under the/usr directory; in two ways;

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/7D/44/wKioL1bkGQ2B9UxzAAA0sPXh_yY884.png "title=" 2.png " Width= "height=" 102 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:700px;height:102px; "alt=" Wkiol1bkgq2b9uxzaaa0spxh_yy884.png "/>

3, find in/etc directory in the last week of its content has been modified, and the owner is not the root user is not a Hadoop user files or directories;

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/7D/46/wKiom1bkGKjxmprQAAAeT9a2pW8441.png "title=" 3.png " Width= "height=" border= "0" hspace= "0" vspace= "0" style= "width:700px;height:92px;" alt= " Wkiom1bkgkjxmprqaaaet9a2pw8441.png "/>

4. Find files or directories that are not in or belong to the current system and have been visited in the last week;

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7D/46/wKiom1bkGOOiODEfAAB2WwCV7Pc857.png "title=" 4.png " Width= "height=" border= "0" hspace= "0" vspace= "0" style= "width:700px;height:210px;" alt= " Wkiom1bkgooiodefaab2wwcv7pc857.png "/>

5. Find all files that are larger than 1M and type ordinary files in/etc directory;

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7D/46/wKiom1bkGSnBTaMtAAAXmGWOsUY664.png "title=" 5.png " Width= "height=" border= "0" hspace= "0" vspace= "0" style= "WIDTH:700PX;HEIGHT:89PX;" alt= " Wkiom1bkgsnbtamtaaaxmgwosuy664.png "/>

6, look for all the users in/etc directory do not have permission to write files;

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7D/44/wKioL1bkGdCCeCUXAABgojVx6hg692.png "title=" 6.png " Width= "height=" 225 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:700px;height:225px; "alt=" Wkiol1bkgdccecuxaabgojvx6hg692.png "/>

7, Find/etc directory at least one class of users do not have permission to execute files;

~] #find/etc-not-perm-111-type f-ls

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7D/46/wKiom1bkGXTTHtEjAABk1fVy81M704.png "title=" 7.png " Width= "height=" 212 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:700px;height:212px; "alt=" Wkiom1bkgxtthtejaabk1fvy81m704.png "/>

8, find/etc/init.d/directory, all users have execute permission, and other users have write permission to all files;

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7D/46/wKiom1bkGe-DvtV9AAANmIWK9zE519.png "title=" 8.png " Width= "height=" border= "0" hspace= "0" vspace= "0" style= "width:700px;height:33px;" alt= " Wkiom1bkge-dvtv9aaanmiwk9ze519.png "/>


Find the Linux File Finder tool (Detailed)

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.