How to add specific directories to "updatedb" (locate) search path?

With the "mlocate" implementation, use the --database-root option, without pruning anything. In the updatedb(8) man page:

-U, --database-root PATH
    Store only results of scanning the file system subtree rooted at
    PATH  to  the  generated  database.   The  whole  file system is
    scanned by default.

But you may need to use a separate output file (--output) too. I'm not sure that you can merge both databases (you can try).

Other implementations may have similar options.


There's no option for that in updatedb.conf. You'll have to arrange to pass options to updatedb manually.

With updatedb from GNU findutils, pass --localpaths.

updatedb --localpaths '/ /media/win_c/somewhere/Music /media/win_c/somewhere/Photos'

With updatedb from mlocate, there doesn't appear a way to specify multiple roots or exclude a directory from pruning, so I think you're stuck with one database per directory. Set the environment variable LOCATE_PATH to the list of databases:

updatedb --output ~/.media.mlocate.db --database-root /media/win_c/somewhere --prunepaths '/media/win_c/somewhere/Videos'

export LOCATE_PATH="$LOCATE_PATH:$HOME/.media.mlocate.db"