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

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.)

Asked By: ionh

||

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.

Answered By: vinc17

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"

gotscha now i got it.. or?
mlocate is not that easy but this works quite good
for each -U, –database-root PATH in mlocate it seems you need a new db!?

Usage: <script> ‘term’

#!/bin/dash


dbfile="$HOME/.recordings.locate.db";
daysToUpdate=7;
create=0;

# list of paths
paths="/master/media/music /media/recordings";

# list of terms
termA=$( echo "$1" | sed 's/ /\ /g' );
termB=$( echo "$1" | sed 's/ /_/g' );

# realtime scan:
#find $paths -iname "*$termA*" -o -iname "*$termB*"


# -- 

if [ ! -f "$dbfile" ]; then
    create=1;
fi


if [ "$create" -ne 1 ] && [ $(find "$dbfile" -mtime +$daysToUpdate -print) ];
then
    echo "File $dbfile exists and is older than $daysToUpdate days"
    create=1;
fi


if [ "$create" = "1" ] ; then
    echo "Update custom dbs please wait...";
    touch "$dbfile"; # mark for inside actions
    cnt=0;
    for path in $paths
    do
        echo "scan: $path to $dbfile.$cnt";
        updatedb -l 0 -U $path -o "$dbfile.$cnt";
        cnt=$(expr $cnt + 1);
    done
fi


cnt=0;
for path in $paths
do
    echo "scan: $path of cache $dbfile.$cnt";
    locate -d "$dbfile.$cnt" $termA
    locate -d "$dbfile.$cnt" $termB
    cnt=$(expr $cnt + 1);
done
Answered By: f b
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.