The Linux command find

Source: Internet
Author: User

Find is a search under the directory file directory tool, and unlike locate it is accurate to find, so for a lot of content in a large directory it will be slower, but it is very powerful, strong to I have to summarize here.

Find command format:

Find [Options] directory [matching mode] [processing action], where the directory must exist, because he is in the directory to query the file directory.

Matching Criteria:

To find by file name:

-name matching mode: Finds the directory of files matching the pattern in the specified directory.

By the owner of the document, the genus Group, the UID; GID Lookup:

-user USERNAME: In the specified directory to find the owner of the USERNAME Directory of files.

-group GROUPNAME: Finds the file directory belonging to the group GROUPNAME under the specified directory.

-uid uidnum: Locate the file directory under the specified directory that belongs to the main UID uidnum.

-gid gidnum: Locate the file directory belonging to the group GID Gidnum under the specified directory.

-nouser: In the specified directory, locate the file directory that is not owned by the master.

-nogroup: The specified directory looks for a file directory that does not belong to a group.

To find by file type:

-type-f: looks for normal files under the specified directory.

-type-d: Finds the directory under the specified directory.

-type-l: Locate the linked file under the specified directory.

-type-b: Finds the block file under the specified directory.

-type-c: Finds the character file under the specified directory.

-type-s: Looks up the socket file under the specified directory.

-type-p: Locate the pipeline file under the specified directory.

To find by the timestamp of the file:

Time:

By day:

Atime: The time that the file was last modified by metadata (Inod).

CTime: The last time the file was accessed.

Mtime: File Last modified data (block).

By points:

Amin: The time that the file was last modified by metadata (Inod).

Cmin: The last time the file was accessed.

Mmin: File Last modified data (block).

They are followed by the way the time is expressed:

[-atime-ctime-mtime] #: The file directory from # days to #+ days before the start of executing the Find command.

[-atime-ctime-mtime] +#: From # days before execution of the find command to # days ago.

[-atime-ctime-mtime]-#: From # Days to the file directory between the Execute Find command.

According to the permissions of the file:

How permissions are represented:

-perm Mode (# # #): The right to match only the file is # # #的文件目录 (exact permission lookup).

Example: 755: The file directory that matches only the file's permissions is rwxr-xr-x.

-perm/mode (/###): The owner of a matching file has # permissions or a group has # permissions or someone else owns #

The file directory for permissions. (Three # Just represents the number is not necessarily the same)

For example:/111: Matches a file directory in which the owner owns X or the genus group has X or X. But it's important to note that

As long as the file has this permission on the line, as for the other permissions are what match, for example; 700 also matches.

-perm-mode (-###): The owner of the matching file has # permission and belongs to the group # permission and other users have #

The file directory for permissions.

For example:-444: Match belongs to the owner R and the group has r go to other users have R permissions to the file directory. Same

It is important to note that as long as you have this permission to satisfy the condition, not the exact full permissions.

Handling actions:

-ls (Exex ls-l {} \;): The file directory found by find is exported to the Ls-l long format.

-print: Prints the file directory found by find, which is the default.

-fls file path: Locate the Find file directory in this specified file.

-delede: Delete the file directory found by find.

-exec command {} \; Use this time to remember that find finds the file directory is placed in {}, so you can use the command

to manipulate the file directory found by find, note that {} must be followed by a space and-exec the end flag is

" ;", but a lot of ";" has a special meaning, so in It is preceded by "\" to escape.

Find ... | Xargs command: The file directory found by find will be piped to Xargs, and Xargs will give it to it

The following commands are operated (unlike-exec, where xrags is processed in batches of these file directories while the exec

This is done at once, so that when the file directory is too large, it backing system performance.

Logic:

-A: With

-O: Or

-not: Non-

-not (-user username1-a USERNAME2): The file directory belongs to USERNAME1 or USERNAME2.

-not (-user username1-o USERNAME2): The file directory does not belong to USERNAME1 or USERNAME2.

As for the match pattern, the match is done using the wildcard wildcards regular expression.

-

Find of Linux commands

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.