Linux find command-path-prune Usage Details

Source: Internet
Author: User

Link: http://myid520.blog.163.com/blog/static/154418420077259428204/

In Windows, you can search for files in some paths or not in some paths, the following uses the find command in Linux and Its-path-prune parameter to check how this function is implemented in Linux.

If you search for files in the current directory, and the current directory contains many files and directories (Multi-Level Directories), including dir0, dir1, and dir2... directory and dir00, dir01... dir10, dir11....

1. Search for all TXT suffix files in the current directory

Find./-name *. txt

2. Search for TXT suffix files under the dir0 directory and subdirectory in the current directory

Find./-path './dir0 *'-name *. txt

3. Search for the TXT suffix file in the dir0 sub-directory dir00 and its sub-directories in the current directory.

Find./-path '* dir00 *'-name *. txt

4. Search for TXT suffix files in directories other than dir0 and subdirectories

Find./-path './dir0 *'-a-prune-o-name *. txt-print

Note:-A should be the abbreviation of and, which means the logical operator 'or' (&);-O should be the abbreviation of or, it indicates the logical operator 'and' (|).-Not indicates non.

The command line means: If the directory dir0 exists (that is, the left side of-A is true), evaluate the value of-prune and-prune returns the true value, 'and' logical expressions are true (that is,-path '. /dir0 * '-a-Prune is true), the find command will find and print the TXT suffix file in a directory other than this directory; if the directory dir0 does not exist (that is, the left side of-A is false), do not ask the value-prune. If the logical expressions 'and' are false, search for all TXT suffix files in the current directory.

5. Search for TXT suffix files in directories other than dir0, dir1, and subdirectories

Find./\ (-path './dir0 *'-o-path'./dir1 * '\)-a-prune-o-name *. txt-print

Note: parentheses () indicate the combination of expressions. That is, it indicates that shell does not give a special explanation for the subsequent characters, but leaves it to the find command to explain its meaning. Since the command line cannot directly use parentheses, you need to use the backslash '\' to compress (that is, the '\' to enable the command line to recognize the parentheses ). Note that spaces are required on both sides.

6. Search for TXT suffix files under dir0, dir1, and subdirectories

Find./\ (-path './dir0 *'-o-path'./dir1 * '\)-a-name *. txt-print

 

+ 1. Search for TXT suffix files in all directories named dir_general

Find./-path '*/dir_general/*'-name *. txt-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.