Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a strange question, and i am not sure this is something doable at all, thats why i am asking it to the SuperUser :)

So, imagine that you have your filesystem with some mount points for additional partitions.

say something like

/drives/driveA/partitionA /drives/driveA/partitionB /drives/driveB/partitionA ... etc.

now, if all these partitions are mounted in their respective mountpoints, running updatedb would index all the content in their filesystem. Good.

Now, I am trying to set up a sort of low consumption, low hard disk wearing file server, where i would like to use automount, where i would like to have files indexed, but where i dont want to run the indexing on these additional drives every day.

So what i want to achieve is to run updatedb in such a way that some paths (in my case those paths above) could be excluded from the indexing, BUT at the same time without trashing the previous content indexed for those paths.

i see that updatedb has several "pruning" options, that let us exclude certain paths from the indexing process. But this also implies discarding all the content information related to those paths. Instead i would like to exclude certain paths, retaining what has been previously already indexed in those paths.

Does anyone have an idea how to achieve this with mlocate, or what other tool to use for this? thanks

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Create several indexes

The key to this answer is that mlocate allows the user to search several database files. If you take this into consideration, then having complex options for excluding or including files from certain paths depending on whether or not the filesystem is mounted becomes less important.

The provided example can be adopted to your situation with little effort. Generally speaking, you can create several index files with updatedb and update them simultaneously or one by one as frequently you want (via cron, for example).

If there is a global /etc/updatedb.conf, then it is probably wise to exclude paths that will have their own indexes, because otherwise you will get double results when searching all indexes as suggested in the example.

When all as many indexes as required have been created, proceed with a shell function such as shown below to automatically include all indexes when doing a search:

function locate {
    /usr/bin/locate \
      -d /var/tmp/default.mlocate.db \
      -d /my-stuff/mlocate-index2.db $@ 

Relevant documentation

(do a man updatedb too)

man locate *scroll scroll scroll*

-d, --database DBPATH
  Replace the default database with DBPATH. DBPATH is a :-separated list of
  database file names. If more than one --database option is specified, the
  resulting path is a concatenation of the separate paths.

  An empty database file name is replaced by the default database. A database
  file name - refers to the standard input. Note that a database can be read 
  from the standard input only once.


# updatedb -o /home/jaroslav/.locate/media-music.db -U /mnt/media/media/ \
    -n images \
    -n movies \
    -n steamapps \
    -n pr0n -v

# locate -i glass -d /home/jaroslav/.locate/media-music.db| wc -l
# locate -i glass -d /home/jaroslav/.locate/media-music.db \
                  -d /var/lib/mlocate/mlocate.db  | wc -l
share|improve this answer
Thanks, i was hoping in a similar option, actually, and i did not notice i could do something like this! :) –  Paul Nov 30 '12 at 15:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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