Add Specific Directories to updatedb (locate) Search Path – How to Guide

linuxlocateupdatedb

I keep my digital music and digital photos in directories in a Windows partition, mounted at /media/win_c on my dual-boot box.
I'd like to include those directories—but only those directories—in the locate database.
However, as far as I can make out, updatedb.conf only offers options to exclude directories, not add them.
Of course, I could remove /media from PRUNEPATHS, and then add a whole bunch of subdirectories (/media/win_c/Drivers, /media/win_c/ProgramData…) but this seems a very clunky way of doing it—surely there's a more elegant solution?

(I tried just creating soft links to the Windows directories from an indexed linux partition, but that doesn't seem to help.)

Best Answer

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"
Related Question