Glam Prestige Journal

Bright entertainment trends with youth appeal.

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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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