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

$ find /usr -name *.sh

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

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

为什么不 寻找 工作?

有帮助吗?

解决方案

尝试引用通配符:

$ find /usr -name \*.sh

或者:

$ find /usr -name '*.sh'

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

$ find /usr -name tkConfig.sh

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

$ 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 /usr -follow -name '*.sh'

其他提示

在某些系统(例如 Solaris)上,没有默认操作,因此您需要添加 -print 命令。

find /usr -name '*.foo' -print

为了在磁盘上查找文件,您可以使用瞬时的“定位”(查看每日构建索引)您的示例是:

locate '/usr*.sh'
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top