find的“false”选项的目的是什么?

时间:2021-01-18 08:08:34

According to man find

根据人找到

-false Always false.

错误总是错误的。

What is the purpose of this option? When is it used?

这个选项的目的是什么?什么时候使用?

1 个解决方案

#1


2  

false and true options will be used with complex test expressions in find command.

在find命令中,将对复杂的测试表达式使用false和true选项。


gnu documentation:

find evaluates the expression each time it processes a file. An expression can contain any of the following types of primaries:

查找表达式在每次处理文件时的值。表达式可以包含以下任一类型的主元:

  1. options

    选项

    affect overall operation rather than the processing of a specific file;

    影响整体操作,而不是特定文件的处理;

  2. tests

    测试

    return a true or false value, depending on the file's attributes;

    根据文件的属性返回真值或假值;

  3. actions

    行动

    have side effects and return a true or false value; and

    有副作用并返回真值或假值;和

  4. operators

    运营商

    connect the other arguments and affect when and whether they are evaluated.

    连接其他参数,并影响何时以及是否评估它们。

Combining Primaries With Operators

Operators build a complex expression from tests and actions. The operators are, in order of decreasing precedence:

操作符通过测试和操作构建复杂的表达式。操作符的优先级依次为:

( expr )
    Force precedence. True if expr is true.
! expr
-not expr
    True if expr is false. In some shells, it is necessary to protect 
    the ‘!’ from shell interpretation by quoting it.
expr1 expr2
expr1 -a expr2
expr1 -and expr2
    And; expr2 is not evaluated if expr1 is false.
expr1 -o expr2
expr1 -or expr2
    Or; expr2 is not evaluated if expr1 is true.
expr1 , expr2
    List; both expr1 and expr2 are always evaluated. 
    True if expr2 is true. The value of expr1 is discarded. 
    This operator lets you do multiple independent operations on one 
    traversal, without depending on whether other operations succeeded. 
    The two operations expr1 and expr2 are not always fully independent,
     since expr1 might have side effects like touching or deleting files,
     or it might use ‘-prune’ which would also affect expr2. 
— Test: -true  
    Always true. 
— Test: -false
    Always false.     

find searches the directory tree rooted at each file name by evaluating the expression from left to right, according to the rules of precedence, until the outcome is known (the left hand side is false for ‘-and’, true for ‘-or’), at which point find moves on to the next file name.

找到搜索目录树扎根在每个文件名通过评估表达式从左到右,根据优先级的规则,直到结果是已知的(左边是假的“——”,对“或者”),此时找到转移到下一个文件的名字。

Example : source question

find . \( \! -user xx -exec chown -- xx '{}' + -false \) -o    \
\( \! -group root -exec chgrp -- root '{}' + \) -o \
\( ! -perm 700 -exec chmod -- 700 '{}' + -exec false \; \)

Explanation: ( by perreal)

解说:(perreal当时)

The false predicate evaluated to false for -o and it is used here to prevent short short-circuiting.

false谓词为-o的值为false,这里使用它来防止短路。

if user is not xx make it xx
if group is not root, make it root
if not all permissions are set for the owner, grant all permissions.

Each command is separated by -o and terminated by false so that they are ALL applied to each item.

每个命令被-o分隔,以false结尾,因此它们都应用于每个项。

what is the purpose of false in above command ?

在上述命令中,错误的目的是什么?

or as a logical operator, evaluates to true if any of it's arguments are true, most programming languages stop evaluation and return true (which is called short circuiting). In order to prevent this, you can force each argument to return false and hence evaluate all or'ed terms.

或者作为一个逻辑运算符,如果它的任何一个参数为真,则求值为真,大多数编程语言停止求值并返回真(称为短路)。为了避免这种情况,您可以强制每个参数返回false,从而计算所有或ed项。

#1


2  

false and true options will be used with complex test expressions in find command.

在find命令中,将对复杂的测试表达式使用false和true选项。


gnu documentation:

find evaluates the expression each time it processes a file. An expression can contain any of the following types of primaries:

查找表达式在每次处理文件时的值。表达式可以包含以下任一类型的主元:

  1. options

    选项

    affect overall operation rather than the processing of a specific file;

    影响整体操作,而不是特定文件的处理;

  2. tests

    测试

    return a true or false value, depending on the file's attributes;

    根据文件的属性返回真值或假值;

  3. actions

    行动

    have side effects and return a true or false value; and

    有副作用并返回真值或假值;和

  4. operators

    运营商

    connect the other arguments and affect when and whether they are evaluated.

    连接其他参数,并影响何时以及是否评估它们。

Combining Primaries With Operators

Operators build a complex expression from tests and actions. The operators are, in order of decreasing precedence:

操作符通过测试和操作构建复杂的表达式。操作符的优先级依次为:

( expr )
    Force precedence. True if expr is true.
! expr
-not expr
    True if expr is false. In some shells, it is necessary to protect 
    the ‘!’ from shell interpretation by quoting it.
expr1 expr2
expr1 -a expr2
expr1 -and expr2
    And; expr2 is not evaluated if expr1 is false.
expr1 -o expr2
expr1 -or expr2
    Or; expr2 is not evaluated if expr1 is true.
expr1 , expr2
    List; both expr1 and expr2 are always evaluated. 
    True if expr2 is true. The value of expr1 is discarded. 
    This operator lets you do multiple independent operations on one 
    traversal, without depending on whether other operations succeeded. 
    The two operations expr1 and expr2 are not always fully independent,
     since expr1 might have side effects like touching or deleting files,
     or it might use ‘-prune’ which would also affect expr2. 
— Test: -true  
    Always true. 
— Test: -false
    Always false.     

find searches the directory tree rooted at each file name by evaluating the expression from left to right, according to the rules of precedence, until the outcome is known (the left hand side is false for ‘-and’, true for ‘-or’), at which point find moves on to the next file name.

找到搜索目录树扎根在每个文件名通过评估表达式从左到右,根据优先级的规则,直到结果是已知的(左边是假的“——”,对“或者”),此时找到转移到下一个文件的名字。

Example : source question

find . \( \! -user xx -exec chown -- xx '{}' + -false \) -o    \
\( \! -group root -exec chgrp -- root '{}' + \) -o \
\( ! -perm 700 -exec chmod -- 700 '{}' + -exec false \; \)

Explanation: ( by perreal)

解说:(perreal当时)

The false predicate evaluated to false for -o and it is used here to prevent short short-circuiting.

false谓词为-o的值为false,这里使用它来防止短路。

if user is not xx make it xx
if group is not root, make it root
if not all permissions are set for the owner, grant all permissions.

Each command is separated by -o and terminated by false so that they are ALL applied to each item.

每个命令被-o分隔,以false结尾,因此它们都应用于每个项。

what is the purpose of false in above command ?

在上述命令中,错误的目的是什么?

or as a logical operator, evaluates to true if any of it's arguments are true, most programming languages stop evaluation and return true (which is called short circuiting). In order to prevent this, you can force each argument to return false and hence evaluate all or'ed terms.

或者作为一个逻辑运算符,如果它的任何一个参数为真,则求值为真,大多数编程语言停止求值并返回真(称为短路)。为了避免这种情况,您可以强制每个参数返回false,从而计算所有或ed项。