为什么“查找”不显示此文件?

dot*_*hen 21 shell find quoting wildcards

使用findwith grep,可以定位匹配模式的文件:

# find | grep error
./solr-modifiedSolr4/SolrPhpClient/phpdocs/errors.html
./error_log
./includes/classes/error_log
Run Code Online (Sandbox Code Playgroud)

但是,find单独使用找不到第一个文件:

# find . -name error*
./error_log
./includes/classes/error_log
Run Code Online (Sandbox Code Playgroud)

为什么不使用 with 时find找不到errors.html文件grep?如何find用于显示此文件?

Den*_*ker 42

你需要引用你的论点,error*因为 shell 扩展了它。所以你现在实际运行的是find -name error_log,因为这就是 shell 可以将它扩展到的(error_log在你的当前目录中有一个文件名)。

find . -name 'error*'
Run Code Online (Sandbox Code Playgroud)

是您的用例的正确调用。

  • 另一种写法是`find -name error\*` - 少按一个键;) 这具有相同的效果,`*` 作为文字星号传递给 find 命令,并且不会被你的 shell 扩展 (12认同)
  • 当 shell 出现问题时(它如何解释您的命令行并将所有参数和参数传递给实际命令),重新运行该命令,并在它前面加上 `echo` 命令。所以,如果你运行 `echo find 。-name error*` 它会输出 `find 。-name error_log` (3认同)