找到" false"的目的是什么?选项?

时间:2016-04-09 18:49:25

标签: linux unix command

根据man find

  

-false总是假的。

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

1 个答案:

答案 0 :(得分:0)

protected void Application_BeginRequest() { //CORS if (Request.Headers.AllKeys.Contains("Origin")) { Response.Headers.Add("Access-Control-Allow-Origin", string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["CORS_ORIGIN"]) ? "*" : ConfigurationManager.AppSettings["CORS_ORIGIN"]); Response.Headers.Add("Access-Control-Allow-Methods", "OPTIONS, GET, POST, PUT, DELETE"); Response.Headers.Add("Access-Control-Allow-Headers", "Access-Control-Allow-Methods, Access-Control-Allow-Origin, Content-Type, Accept, X-Requested-With, Session"); //handle CORS pre-flight requests if (Request.HttpMethod == "OPTIONS") Response.Flush(); } } false选项将与true命令中的复杂测试表达式一起使用。

gnu documentation

find每次处理文件时都会计算表达式。表达式可以包含以下任何类型的原色:

  1. 选项

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

  2. 测试

    返回true或false值,具体取决于文件的属性;

  3. 动作

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

  4. 运营商

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

  5. Combining Primaries With Operators

    运算符根据测试和操作构建复杂的表达式。运算符按优先级递减的顺序排列:

    find

    通过根据优先级规则从左到右评估表达式来查找以每个文件名为根的目录树,直到结果已知(左侧为'-and'为true,true为' -or'),此时find继续移动到下一个文件名。

    示例:source question

    ( 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.     
    

    说明:perreal

    对于-o,false谓词的计算结果为false,此处用于防止短路。

    find . \( \! -user xx -exec chown -- xx '{}' + -false \) -o    \
    \( \! -group root -exec chgrp -- root '{}' + \) -o \
    \( ! -perm 700 -exec chmod -- 700 '{}' + -exec 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. 的目的是什么?

    false作为逻辑运算符,如果其任何参数为真,则求值为true,大多数编程语言停止求值并返回true(称为短路)。为了防止这种情况,您可以强制每个参数返回or,从而评估所有false'ed条款。