bug-findutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: limiting the directory to locate and search by file type


From: Peng Yu
Subject: Re: limiting the directory to locate and search by file type
Date: Mon, 7 Nov 2011 18:11:02 -0600

On Mon, Nov 7, 2011 at 5:47 PM, James Youngman <address@hidden> wrote:
> On Mon, Nov 7, 2011 at 10:02 PM, Peng Yu <address@hidden> 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

[Prev in Thread] Current Thread [Next in Thread]