1

I'm having trouble with the find command in bash. I'm trying to find a file that ends with .c and has a file size bigger than 2000 bytes. I thought it would be:

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

But obviously that isn't correct.

What am I doing wrong?

4

3 回答 3

6

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

于 2012-10-23T15:24:55.003 回答
-1

Try this:

find $HOME -type f -size +2000c -name *.c
于 2012-10-23T15:22:44.270 回答
-1

尝试以下操作:

find $HOME -type f -size +2000c -name *.c
于 2012-10-23T15:26:42.133 回答