Find commands and explanations

Source: Internet
Author: User

You need to use the Find command when you need to find a file or directory in your system . It can traverse all the hierarchies under a given path to find the desired file. The Find command allows for real-time lookups, exact lookups, and it needs to traverse all levels in a given directory, all at a slightly slower pace.

1, the format of the command:

Find [OPTIONS] [ path ] [ condition ] [ processing Action ]

2, the parameters of the command:

Path: Given a specific search starting path, the default is the current directory.

Find criteria: Find criteria, can be based on file name, affiliation, file type, size, permissions, time and so on to find.

Handling actions: After the lookup is complete, you can specify the operation of the command on the result.

3. options for the command:

Find by file name

-name : Search by the given name;

-iname: Look for names that are not case-sensitive;

Find based on file dependencies

-user: According to the owner of the search;

-group: Search according to genus Group;

-uid: Search by uid ;

-gid: Search by gid ;

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

-nogroup: Find files without a group;

Find by File type:

-type Type:

F: ordinary documents;

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:k,M,G

Find by Time stamp:

In ' Days ' units:

-atime: Access Time

-mtime: Modification Time

-ctime: Change Time

In ' minutes ' units:

-amin

-mmin

-cmin

Search by permissions:

-perm [/|-]mode

Mode: precise permission matching;

/mode: Any one kind of user's permission is satisfied with the condition;

-mode: Each type of user's rights in each of the same time meet the condition is satisfied;

Condition combination:

-A: ' With ' operation, default option;

-O: ' or ' Operation;

-not \! : ' Non ';

4. Handling Actions

-print: standard output; (default)

-ls: Execute the 'ls-l' command on the search results, and output the details of the file;

-delete: Delete a found file

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

-ok COMMAND {} \; : Executes on each file that is found COMMAND command, interactive operation;

-exec COMMAND {} \; : Executes on each file that is found COMMAND order;

5. Other Notes

the results found by find are given at once and passed to the following commands, but some commands cannot accept too long parameters.

For example: Find/etc-type F | ls-l this is wrong. At this point, you can use the xargs command.

Example:find/etc-type F | xargs ls-l

Xargs can read in to find information, and is distinguished by a blank or newline character. Separates the found information into multiple parameters.

6. Instance Operations

① Find all the. txt files in/home and display

find/home-type f-a-name " *.txt " -ls

② find files that start with a capital letter

Find/-type f-a-name " [a-z]* " -ls

③ find files that all users can read and write

Find/-type F-perm-007-ls

④ Find all files in/ etc directory where all users have execute permissions and other users have write permissions

find/etc/-type f-a-perm-111-a-perm-002-ls

⑤ Find files or directories that are larger than 1Min the/ etc directory andhave been modified in the last week

find/etc/-size +1m-a-mtime-7-ls

⑥ find All files or directories in the /usr/ directory that do not belong to root,bin , or Hadoop

find/usr/-not \ (-user root-o-user bin-o-user hadoop \)-ls


Find commands and explanations

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.