Mac OS X 上的 mdfind 命令

for*_*ght 6 geektool macos

当我尝试使用 mdfind 命令在 Mac 上查找所有 .txt 文件时,它只返回一个 .txt 文件。所以为什么 ?以及如何使用“mdfind”在我的 Mac 上查找所有 .txt 文件?

somebody@MacAir:~ somebody$ mdfind -name *.txt
/Users/somebody/20160408_2.txtenter 
Run Code Online (Sandbox Code Playgroud)

Spi*_*iff 8

你要这个:

mdfind -name .txt
Run Code Online (Sandbox Code Playgroud)

您会看到,mdfind自动假定通配符,因此您无需尝试将通配符传递给它。

事实证明,由于您没有*mdfind. 相反,您将它提供给 shell,而 shell 正在“通配”,或者将其替换为当前工作目录 ( /Users/somebody/) 中与模式匹配的文件列表*.txt。因此,shell 的真正调用mdfind方式可能更像这样:

mdfind -name 20160408_2.txt SomeOtherFile.txt YetAnotherFile.txt AndSoOn.txt
Run Code Online (Sandbox Code Playgroud)