5

Is there a way to restrict locate output to specific directories on Mac OS X Snow Leopard? I read about using regex on a Ubuntu forum. However, on my mac locate does not accept -r option. I also looked at the man pages for locate on Mac and there is no -r option.

Thank you.

1

Just use shell wildcards in the locate's search pattern - that functionality is a historical feature of the utility and should be supported on all systems.

E.g.:

$ locate '*/dirname/*filename*'

Be sure to use stars around the search string (or at least in front of it) as once you use wildcards locate switches the logic and anchors the search string to beginning and end of the searched material.

0

I think you need to install another version of locate. I do not have a OS X system to check, but it seems that slocate is present in macports, so it should be quite easy to install, and I think it does have the required option.

0

Try mdfind instead.

$ mdfind -onlyin $HOME iTunes

The md* utilities use the same database as Spotlight.

0

You can try to mix it with the grep command, like:

locate hosts | grep ^/etc

or:

locate php | grep -e ^/etc -e ^/usr/local/etc

to look into multiple directories.

If you using this functionality very often, write a wrapper for it.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.