查找具有特定扩展名且超过特定文件大小的文件 [英] Find files with a certain extension that exceeds a certain file size

查看:16
本文介绍了查找具有特定扩展名且超过特定文件大小的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 bash 中的 find 命令时遇到问题.我正在尝试查找以 .c 结尾且文件大小大于 2000 字节的文件.我以为会是:

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$

但显然这是不正确的.

我做错了什么?

推荐答案

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

看看mane页面中的-name开关:

Have a look to the -name switch in the mane page:

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

请注意最后的建议,即始终将模式括在引号内.选项的顺序不相关.再次查看手册页:

Note the suggestion at the end to always enclose the pattern inside quotes. The order of the options is not relevant. Have, again, a look to the man page:

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 之外的其他运算符.

So, options are, by default, connected with and -and operator: they've to be all true in order to find a file and the order doesn't matter at all. The order could be relevant only for more complicated pattern matching where there are other operators than -and.

这篇关于查找具有特定扩展名且超过特定文件大小的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆