查找具有超过一定文件大小的某个扩展名的文件



我在bash中的find命令遇到了麻烦。我正在尝试找到一个以.c结尾的文件,并且文件大小大于2000字节。我以为是:

find $HOME -type f -size +2000c .c$

,但显然这不是正确的。

我在做什么错?

find $HOME -type f -name "*.c" -size +2000c

在鬃毛页面中查看-name开关:

-name pattern
              Base of  file  name  (the  path  with  the  leading  directories
              removed)  matches  shell  pattern  pattern.   The metacharacters
              (`*', `?', and `[]') match a `.' at the start of the  base  name
              (this is a change in findutils-4.2.2; see section STANDARDS CON‐
              FORMANCE below).  To ignore a directory and the files under  it,
              use  -prune; see an example in the description of -path.  Braces
              are not recognised as being special, despite the fact that  some
              shells  including  Bash  imbue  braces with a special meaning in
              shell patterns.  The filename matching is performed with the use
              of  the  fnmatch(3)  library function.   Don't forget to enclose
              the pattern in quotes in order to protect it from  expansion  by
              the shell.

请注意,最后的建议始终包装在引号内部的模式。选项的顺序无关紧要。再次,请看一下男人页面:

EXPRESSIONS
       The  expression  is  made up of options (which affect overall operation
       rather than the processing of a specific file, and always return true),
       tests  (which  return  a  true or false value), and actions (which have
       side effects and return a true or false value), all separated by opera‐
       tors.  -and is assumed where the operator is omitted.
       If the expression contains no actions other than -prune, -print is per‐
       formed on all files for which the expression is true.

因此,默认情况下,选项与-and操作员连接在一起:为了找到文件,它们必须是正确的,并且该订单根本无关紧要。该订单只能与更复杂的模式匹配有关,而其他操作员除了 -and以外的其他操作员。

尝试以下:

find $HOME -type f -size +2000c -name *.c

尝试以下内容:

find $HOME -type f -size +2000c -name *.c

相关内容

  • 没有找到相关文章

最新更新