Linux Find command

Source: Internet
Author: User

The Find command is a command to search for a file, his syntax format: find [path] [options] [tests] [actions]

1. The path section is the route you specify, which can be an absolute path, such as/usr/bin, or a relative path, such as. 。 If required, you can also specify multiple paths, such as Find/var/home

2. The Options section has the following main option

-depth Search the contents of the directory before viewing the directory itself

-follow Follow Symbolic Links

-maxdepths n Max Search N-tier directory

-mount (or-xdev) does not search for directories in other file systems

3, tests part, can provide to the find command many tests, each kind of test returns the result to have two kinds of possibility: TRUE or the False.find command begins to work, he sequentially applies each kind of test which he has defined to each file that he searches. If a test returns the False,find command, it stops processing the file it currently finds and continues the search. If a test returns the True,finde command, it will continue with the next Test or take action on the current end of the key. The following are common tests

-atime N file was last accessed N days ago

-mtime n files have been modified before n days

The-name pattern file name (not including the pathname) matches the pattern provided, in order to ensure that the pattern is passed to the Find command instead of being handled by the shell, the pattern must always be enclosed in quotation marks

-newer otherfile file to be newer than Ohterfile file

The type of-type C file is C,c is a special type. The most common are D (directories) and F (normal file)

The owner of the-user username file is the specified user username

The operator used to assemble the test

! or-not test to take the reverse

-A or-and two tests must be true

-O or-or two Tests one must be true

4. Actions section

-exec command executes an order. This action must end with a \; character pair.

-ok command is similar to-exec, but he prompts the user for confirmation of each file to be processed before executing the command, which must end with a \; character pair.

-print Print File name

-ls using commands for the current file ls-dils

eg

1, starting from the root directory, look for the file name test, and the full path to the output file

Find/-name Test-print

2. Search for files that are newer than file X, or start with an underscore in the filename

Find/\ (-newer x-o-name "_*" \)-print

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.