Linux exact find--find command

Source: Internet
Author: User
Tags file permissions

The Find command is an exact find tool that can find the exact location of a file, which is much slower than the fuzzy lookup of the Locate command.


Find-search for files in a directory hierarchy

Find [path ...] [Expression]

Path: Refers to the file paths, such as/var,/etc,/tmp, such as working directory;

Expression

Options: such as-user,-root,-size,-perm

Criteria: This search criteria, can be a file name, can be the size of files, can be file permissions information, can be timestamp and so on.

Processing action: The default is-print output, can be-ls display the file's specific property information, or it can be done some kind of operation;


Expression

Search by file name:

-name pattern: Search by file name, support for use, globbing character lookup (*,[^],[],?) such as

-iname pattern: Search for Case of file name ignored

-samefile pattern: Finds the path of other hard-linked files according to the specified file name;

Search based on the inode number of the file:

-inum N:

-links N: Find files with a hard connection number of "n";

-regex Pattern:

-iregex Pattern:

To find by file ownership:

-user uname:

-uid UID: It is based on the user name and/or user ID, to find the owner of the user account of all the files;

-group Gname:

-gid GID: It is based on the group name and/or group ID to find all the files belonging to this group of accounts;

-nogroup: On the permission bit of ownership of the file, there is no group name that only shows the file belonging to the group ID;

-nouser: In the file ownership of the permission bit, there is no main name only display the main ID of the file;

Depending on the type of file:

-type C:

C represents a single-character descriptor for a file type, which includes:

B: Block device

C: Character device

D: Catalogue

F: Normal file

L: Symbolic link

P: Piping

S: socket

-xtype

The search result of the symbolic connection file needs other selection of mates to find, otherwise it is the original file that is linked;

To find based on a timestamp:

Search in days as a unit of time:

-atime [+|-]n: Finding based on access timestamp

-ctime [+|-]n: Finding based on change timestamp

-mtime [+|-]n: Finding based on modified timestamp

N:[N,N+1)

+n:[n+1,+oo)

-n:[now,n)

In a simple language, it is the result.

To find in minutes:

Amin [+|-]n:

Cmin [+|-]n:

Mmin [+|-]n:


To find the file size:

-size N[CWBKMG]

N: (N-1,n]

+n:[n,+oo)

-N:[0,N-1]


The logic operator combines the preceding conditions with the judgment of complex logic:

-A | -and: Logic and operation, the default is the logical operation, can be omitted;

-O | -or: logic or operation;

-not |! : Logical non-operation;


Dommergen law is still in force; a&b=! a|! B

To find according to permissions:

-perm [/|-]mode:

Mode: exact permission match, meaning to find a file that must match the specified permission bit exactly;

/mode: In the permission of any one permission bit, as long as there is a go permission to satisfy the condition, that is, to match the success, it can be used as a search result; implicit logic or relationship;

-mode: The permission of each permission bit must contain the specified permission bit, in order to satisfy the condition, the match succeeds, it is used as the search result, and the logic and relation are implied;


Really take the anti-false

False Take Reverse truth

All for true take the reverse of any one is false

All false take the inverse of any one is true

Handling actions:

-print: The results of matching criteria are directly output to the standard output, the default action;

-ls: Displays the results of the matching criteria with the execution results of the "ls-dils" command;

-exec command {} \;

-ok command {} \;

For a qualifying search result, follow the command commands again, {} is a placeholder, meaning: The path information used to refer to the individual files in the Find command's lookup results;


Ex

Find files on the current system that are not owned by the master or group, and have been visited in the last one months, and change their genus to root;

~]# find-nouser-o-nogroup-a-atime 30-exec chown root,root {} \


Attention:

-exec is non-interactive;-ok is interactive;

Many commands cannot be placed behind a pipe, because the pipeline is conveying pure string information, so the commands behind the pipeline generally must be commands to handle strings, and in general, you can use the Xarge command to convert them into parameters that can be processed by the commands behind the pipeline;



Linux exact find--find command

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.