The Mdfind Command on Mac Os X

The Mdfind Command on Mac Os X

When I try to find the all .txt files on my Mac using the mdfind command, it just returns only one .txt file back. So why ? And how to find all the .txt files on my Mac with "mdfind"?

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

1 Answer

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
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.