Команда mdfind в Mac OS X

2173
forAllBright

Когда я пытаюсь найти все файлы .txt на моем Mac с помощью команды mdfind, он просто возвращает только один файл .txt. Так почему же? И как найти все файлы .txt на моем Mac с помощью "mdfind"?

somebody@MacAir:~ somebody$ mdfind -name *.txt /Users/somebody/20160408_2.txtenter  
1

1 ответ на вопрос

5
Spiff

You want this:

mdfind -name .txt 

You see, mdfind automatically assumes wildcards, so you don't need to try to pass it a wildcard.

And it turns out that since you didn't shell-escape your *, you weren't actually passing that wildcard to mdfind like you intended. Instead, you were giving it to the shell, and the shell was "globbing", or replacing it with the list of files in your current working directory (/Users/somebody/) that matched the pattern *.txt. So how the shell was really calling mdfind was probably something more like this:

mdfind -name 20160408_2.txt SomeOtherFile.txt YetAnotherFile.txt AndSoOn.txt