11

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

2
  • Which updatedb implementation do you have? There are several. Tell us the output of updatedb --version. Aug 22, 2014 at 23:27
  • Sorry, should've given that - "updatedb (mlocate) 0.26"
    – ionh
    Aug 23, 2014 at 16:33

3 Answers 3

5

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"
0
5

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.

3
  • That's the mlocate implementation. Different updatedb implementations have different options. Aug 22, 2014 at 23:27
  • @Gilles Thanks, indeed I'm using mlocate. I've edited my answer. I would be surprised if other implementations did not have a similar option.
    – vinc17
    Aug 22, 2014 at 23:30
  • Using "locate" in Ubuntu the command is what you answered, also add export as first answer point out just to sure locate include the root path and the path just added Sep 14, 2016 at 16:09
0

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

in 2023: plocate is debians default now, this wont work well anymore!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .