Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

>For what it's worth, the terminal interface to the Spotlight database is "mdfind".

Yeah I realize that, but find is a stronger tool for the use case because it also allows wildcards to be specified in the name.

>your "find" will search in and below

Your "mdfind" will also search in and below the current directory.

find also has -depth which can be used to tell it to search only this directory.

mdfind has -onlyin to tell it what directory to search in, but it still recurses down. Does it have an option to limit this? Please do tell.

>for files that exactly match "somestring"

Well find also allows wildcards though. So not necessarily exactly… somestring is just an example.

Does mdfind allow wildcards?

Also find is fun to combine with grep to inspect file contents, especially since it has the -print0 option…

    find . -type f -name "*.py" -print0 | xargs -0 grep somestring 
Please tell me how to do this with mdfind, I would love to know!


you could also just have find run the grep for you as well

    `find . -type f -name \*.py -exec grep homestring {} \;`
It's not exactly equivalent, however, I often will just use find directly for simple actions.


mdfind searches contents by default, thanks to the Spotlight index.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: