查找超过特定文件大小的特定扩展名的文件

问题描述:

我遇到了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其他运算符更复杂的模式匹配。

+0

谢谢你,顺便说一句,没有命令的顺序重要的发现声明。如果我想要,可以输入find $ HOME -name“* c”-type f -size + 2000c吗? – Unknown

+1

用于引用glob。 – l0b0

+1

@BernieMacinflor,不要害怕man page。用你评论的答案编辑答案。 ;) – Zagorax

试试这个:

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

尝试以下操作:

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