1

bashのfindコマンドで問題が発生しました。.cで終わり、ファイルサイズが2000バイトを超えるファイルを見つけようとしています。私はそれが次のようになると思いました:

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

しかし、明らかにそれは正しくありません。

私は何が間違っているのですか?

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.

パターンを常に引用符で囲むという最後の提案に注意してください。オプションの順序は関係ありません。もう一度、manページを見てください。

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演算子に接続されています。ファイルを検索するには、オプションがすべてtrueである必要があり、順序はまったく関係ありません。順序は、以外の演算子が存在する、より複雑なパターンマッチングにのみ関連する可能性があります-and

于 2012-10-23T15:24:55.003 に答える
-1

これを試して:

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 に答える