How do I get mlocate to only index certain directories?

18,124

Solution 1

You can use the -U option (--database-root PATH)

updatedb -l 0 -U /home/user/music -o /home/user/databasefile

-o writes to the output file

-l 0 makes that you can read it, otherwise it is only accessible for locate

Then you can then use it like:

locate -d /home/user/databasefile Dylan

-d sets the databasepath

To use mlocate with more than one root directory, simply create two databasefiles, and use locate with two databasepath's options like this:

locate -d /home/user/dbfile1 -d /home/user/dbfile2 searchstring

To sum it up and answer the question more specific:

updatedb -l 0 -U /home -o /home/user/home_dbfile
updatedb -l 0 -U /data -o /home/user/data_dbfile
locate -d /home/user/home_dbfile -d /home/user/data_dbfile Dylan

Solution 2

Edit the file /etc/updatedb.conf

Set up PRUNEPATHS with the directories you DO NOT want to search

PRUNEPATHS="/tmp /var/spool /media"

PRUNEPATHS: A whitespace-separated list of path names of directories which should not be scanned by updatedb. Each path name must be exactly in the form in which the directory would be reported by locate. By default, no paths are skipped.

Note that all of the above configuration information can also be changed or updated through the command line options to the utility updatedb.

Solution 3

I found something else you could try:

  1. QuickSearch - "So my SearchTool use a different way: it uses 'ls' command to list content of searched folder, then does the search on that output. This way search speed is very fast (except for the first time it has to make the 'ls' output)."

Not very sure about indexing.

  1. Use tool tracker-gui
  2. Pretty lame solution sudo find "place your search directories here" > files.list grep 'filename' files.list
Share:
18,124

Related videos on Youtube

Andrew Ferrier
Author by

Andrew Ferrier

IBM Worklight, Mobile & Dojo expert. Work with a wide ranging of mobile and web technologies and platforms. Lead IBM's EMEA Pan-IOT Mobile Software Services Team.

Updated on September 18, 2022

Comments

  • Andrew Ferrier
    Andrew Ferrier over 1 year

    I'd like to use mlocate on my Ubuntu server, but only to index certain directories (e.g. /home and /data, but not everything under /). However, mlocate's standard configuration works the opposite way; you specify the paths you want to remove (with PRUNE_PATHS).

    Is there any easy way to achieve this, or any similar utility that will do what I want? (note: it should maintain an index like mlocate, so find is not acceptable, for example) Thanks.

  • Andrew Ferrier
    Andrew Ferrier almost 12 years
    No, that's the exact opposite of what I want. This will index everything except those directories.
  • LnxSlck
    LnxSlck almost 12 years
    You can set PRUNEPATHS with everything except your directories. This way, it will only scan your directories.
  • Andrew Ferrier
    Andrew Ferrier almost 12 years
    OK, thanks for the clarifying edit. That's a bit impractical, because as I add subdirectories alongside directories I want to index, I'd have to remember to add them to PRUNEPATHS. However, it would work. Thanks for the suggestion.
  • LnxSlck
    LnxSlck almost 12 years
    Yes i know, but i can't find much info on mlocate to do that. Can't you use something like find?
  • Andrew Ferrier
    Andrew Ferrier almost 12 years
    No, I have a lot of data, so it's important that it's indexed. Have clarified in question.
  • jokerdino
    jokerdino over 11 years
    Try not to add multiple answers. If necessary, edit the existing answer and include more information. Thanks.
  • LnxSlck
    LnxSlck over 11 years
    Yes, i will do that
  • Andrew Ferrier
    Andrew Ferrier over 10 years
    Upvoting, as this is a partial answer. However, it only allows for whitelisting one path. My question was specifically about how to whitelist more than one path.
  • Janghou
    Janghou over 10 years
    Improved the answer and for easier handling I suggest create an alias
  • Andrew Ferrier
    Andrew Ferrier over 10 years
    good answer! I didn't realise you could search in two databases in parallel, thanks for the clarification. I am going to mark this accepted unless a better answer arrives!
  • Gaia
    Gaia over 7 years
    Is updatedb -l 0 -U /home/user/music recursive? Doesn't seem to be in my case