Restrict search of locate to specific directories

locateosxsearch

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.

Best Answer

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.

Related Question