为什么 **find** 没有找到任何东西?

2024-03-25

我正在寻找安装在我的系统上的 shell 脚本文件,但是find不起作用:

$ find /usr -name *.sh

但我知道那里有大量的脚本。例如:

$ ls /usr/local/lib/*.sh
/usr/local/lib/tclConfig.sh  
/usr/local/lib/tkConfig.sh

为什么不find work?


尝试引用通配符:

$ find /usr -name \*.sh

or:

$ find /usr -name '*.sh'

如果您碰巧有一个匹配的文件*.sh在当前工作目录中,通配符将在 find 看到它之前展开。如果您的工作目录中碰巧有一个名为 tkConfig.sh 的文件,find命令将扩展为:

$ find /usr -name tkConfig.sh

它只会找到名为 tkConfig.sh 的文件。如果您有多个匹配的文件*.sh,你会得到一个语法错误find:

$ cd /usr/local/lib
$ find /usr -name *.sh
find: bad option tkConfig.sh
find: path-list predicate-list

同样,原因是通配符扩展到两个文件:

$ find /usr -name tclConfig.sh tkConfig.sh

引用通配符可防止其过早扩展。

另一种可能性是 /usr 或其子目录之一是符号链接。find通常不会点击链接,因此您可能需要-follow option:

$ find /usr -follow -name '*.sh'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么 **find** 没有找到任何东西? 的相关文章