Find command-path-prune usage in Linux

Source: Internet
Author: User

Excerpt from: http://www.cnblogs.com/hopeworld/archive/2011/04/08/2009252.html

In Windows, you can find files in some paths, or you can set the file to not be found in some paths, and use the Find command in Linux with its-path-prune parameter to see how this function is implemented in Linux.

If the file is located in the current directory, and the current directory has a lot of files and directories (multi-level directory), including DIR0, Dir1 and Dir2 ... and other directories and dir00, Dir01...dir10, Dir11 ... such as subdirectories.

1. Find all txt suffix files in the current directory

Find./-name *.txt

2. Find the txt suffix file under the Dir0 directory and subdirectories under the current directory

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

3. Find the TXT suffix file under the subdirectory dir00 and its subdirectories under the DIR0 directory under the current directory

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

4. Find the txt suffix file in a directory other than Dir0 and subdirectories

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

Description:-A should be an abbreviation for and, meaning logical operator ' or ' (&&); -O should be an abbreviation of OR, meaning the logical operator ' with ' (| |),-not represents non.

The command line means: If the directory dir0 exists (that is,-a left is true), then the-prune value is evaluated,-prune returns True, ' and ' the logical expression is true (that is,-path './dir0* '-a-prune is true), The Find command will look for the txt suffix file in a directory other than this directory and print it out, if the directory dir0 does not exist (that is, a left is false), then no value-prune, ' and ' logical expression is false, the current directory to find all txt suffix files.

5. Find the txt suffix file in a directory other than Dir0, Dir1, and subdirectories

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

Note: parentheses () denote the combination of expressions. This instructs the shell not to give a special explanation of the characters that follow, leaving the Find command to explain its meaning. Because the command line cannot use parentheses directly, you need to use a backslash ' \ ' to make a change (that is, the ' \ ' transpose character makes the command line aware of the parentheses). Also note that ' \ (', ' \ ') ' requires spaces on both sides.

6. Find the txt suffix file in dir0, Dir1, and sub-directories

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

7. Find the txt suffix file in all directories named Dir_general

Find./-path ' */dir_general/* '-name *.txt-print

Find command-path-prune usage in Linux

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.