【问题标题】:How do I find a file containing using wildcard on Linux?如何在 Linux 上找到包含使用通配符的文件?
【发布时间】:2020-12-26 13:50:33
【问题描述】:

我想知道是否可以将 find 与通配符一起使用:

我使用这个命令,但是我有一个错误

find -type f -name /target/*.zip

【问题讨论】:

  • 从您的帖子中不清楚,您正在搜索什么文件。 @Barmar 建议的解决方案假定您正在寻找低于/targetany zip 文件,即/target/foo/bar.zip,但不是/foo/target/bar.zip。这种理解正确吗?

标签: linux bash macos shell find


【解决方案1】:

您需要将通配符放在引号中,否则在运行命令之前它会被shell扩展。

它应该只是一个文件名,而不是路径名。开始搜索的目录应该是过滤器规范之前find 的参数。

find /target -type f -name '*.zip'

【讨论】:

  • 由于 OP 明确提到了 bash,也许像 shopt -s globstar; echo /target/**/*.zip 这样的东西也是一种选择。这取决于应如何进一步处理名称。
猜你喜欢
  • 2013-06-02
  • 2011-11-04
  • 1970-01-01
  • 2017-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多