gpt4 book ai didi

linux - 查找具有超过特定文件大小的特定扩展名的文件

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:30:18 25 4
gpt4 key购买 nike

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

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

但显然这是不正确的。

我做错了什么?

最佳答案

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

查看 man 页面中的 -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 之外的其他运算符。

关于linux - 查找具有超过特定文件大小的特定扩展名的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13033832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com