On Mon, Nov 7, 2011 at 5:47 PM, James Youngman <j...@gnu.org> wrote:
> On Mon, Nov 7, 2011 at 10:02 PM, Peng Yu <pengyu...@gmail.com> wrote:
>> Hi,
>>
>> For 'find', I can specify which directory (directories) to perform the
>> search. It seems that there is no such an option for 'locate' to
>> restrict the search to certain directory rather than everything in the
>> database (specified by -d).
>
> You can achieve this by using locate --regex.

Suppose I want to restrict the search to /tmp, what regex I should specify?

>> Also 'find' offer the option -type, which allows me to search based on
>> the file type. But I don't see there is a corresponding option in
>> locate.
>
> Correct.
>
>> Is my observation correct? Is there a way to do the above two
>> operations with /locate'?
>
> locate --null --regex whatever | xargs --null sh -c 'for file; do test
> -f "$file" && mycommand "$file"; done' fnord

Doing file test will be slow, as I think that the point of locate is
to avoid accessing the filesystem to speedup. Is there any development
on adding filetype information to the database so that it will
searchable within the database.

-- 
Regards,
Peng

Reply via email to