A few examples of the Find command parsing (-a,-o,-path,-wholename,-prune,-print)

Source: Internet
Author: User
Tags split

A: Basic mode and default rules for find

The basic mode of find is find [path] [Express]/*man Find top command format */

Path can be omitted, default is the current directory,

Express is also differentiated into options (optional) +tests (conditional) +actions (action), Express can be logically composited

Express, the options are not introduced first,

Test condition Yes the result is true and false, can be omitted, if the condition is omitted, then the default is true,ture to perform action actions

Actionf action can also be omitted, the default action is-print, that is, to do the output

From the above two can be seen also, the entire express omitted, is to execute-print, print out all directory items (including directories and files).

Figuring out the mode of find, it's a lot clearer. The first command: Find-true-o-name-print          is a compound expression, divided into two sub-expressio n do logic or          previous section-true, only Test has no action, default is-print          because it is logical OR, the front is true, The latter part of the-name-print can be omitted not to see          This command is equivalent to: Find          All directory entries (directories and files) Article II: Find-true-name-print          Just an expression         -true-nam E This is a two condition, equivalent to-true-and-name   equivalent-name          -name The full format is-name pattern, the back if not add File mode p Attern, the pattern is null, directory entries (files and directories) are not nullable, so the match fails, test is false          This command is equivalent to: find-name- Print, equivalent to find-false Third command: find-true-a-print-a-name a-a-print            This command is worse than the first one. The key is, the first command is or action, this command is with the operation            or operation, the front is correct, do not execute behind,            and operation, the equivalent of a before and after the command to write together, from left to right to openFirst, the operation is encountered, the test is based on the original conditions and new conditions            See the third command: find-true-a-print-a-name a-a-P Rint            This command is equivalent to: Find-true-print-name a  -print        &N Bsp   Start from left to right:                   -true, which is a test, when the condition is true (when expression is not finished, the To not perform the default-print)                   -print, is an action, output                     -name A, is a test, formed with the previous-true and:-true-and-name A, true if the file name is a, no False                     -print, is an action that executes when the current test is true  & nbsp           So the result of this command is: A file plays two times, other files play once fourth command: find-true-a-print-o-name a-a-print        This command takes precedence over a command, in a logical operation, with a worry-ahead or action (as in C)          So this command is equivalent to: Find-true-print-o-nam E a-print &NBsp;       -o, referring to the handling of the first second command, no longer explaining the fifth command, is an example of man find:  find. -wholename './src/emacs '-prune-o-print two points-wholename or-path replacement, the GNU find newer version, these two have no difference this command, use-prune,   note Here-prune is an action, not test, and then split path for this find command., that is, the current directory expression is a compound sentence, with-o split into two clauses, only the previous clause false when the second clause is executed            First:-wholename './src/emacs '-prune               &NBSP ;   Here the test condition is:-wholename './src/emacs ',                      &NBS P;action:-prune, perform "Select subdirectory resolution",                      if test result is false, That does not match to./src/emacs, does not execute action, clause result is false                      if test The result is true, which matches to  ./src/emacs, then the action is executed: Skip                  to combine: When the catalog item (file or directory) matches./src/emacs, execute prune, i.e. "Do not enter this directory", or skip the directory resolution, expression is true                             When catalog items (files or directories) does not match./src/emacs, expression is true            Second:-print          &NB Sp       This clause omits test, the default is True,-print is Acion, that is, lost                  The second statement is executed in the case of false in the previous statement, so the entire compound expression is, skipping the directory:./src/emacs and does not enter the directory, output other directory entries

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.