8

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 1

10

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
  • Testing this because of another Q in Ask Different… -name "Micro" returns all the Microsoft apps, but -name "soft" doesn't. It seems to be assuming "begins with" rather than "contains"
    – Tetsujin
    Commented Mar 27, 2022 at 14:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .