Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

If I understand correctly, the database locate relies on is just for files on partitions of internal HDDs. I wonder if it is possible to use locate on external HDDs?

share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted

The locate database is generally configured to omit files on removable disks, since they can't be assumed to be there later. It can be configured through a file such as /etc/updatedb.conf (the location depends on which of the several locate programs you use and how it is configured by your distribution).

For a removable disk, it is probably better to keep the database in a separate file. Run

updatedb --localpaths=/media/my_removable_disk --output=/var/cache/locate/my_removable_disk.locatedb 

to update the database. Add /var/cache/locate/my_removable_disk.locatedb to the environment variable LOCATE_PATH; for reasonably recent versions of GNU locate, an empty path component stands for the default path, so you can use

export LOCATE_PATH=:/var/cache/locate/my_removable_disk.locatedb

If you want to keep the locate database on the removable disk, don't add the path to LOCATE_PATH, because locate stops looking if one of the database files is missing. A wrapper script would be better:

locates () {
  locate "$@"
  for d in /media/*; do
    locate -d "$d/.locatedb" "$@"
  done
}
share|improve this answer
    
Just a note for future reference, the command is a tad different for mlocate users: updatedb --database-root /media/my_removable_disk --output=/var/cache/locate/my_removable_disk.locatedb --prunepaths "" --prunefs "" –  Ivan Apr 2 '13 at 10:54
add comment

The config file is here: /etc/updatedb.conf, so if you didn't add anything, just mount your HDD, and do updatedb, then you would be able to search for files on external HDD partitions.

share|improve this answer
    
Thanks! If I disconnect my external HDD from my computer, the config file will be updated automatically later to remove info about the external HDD? –  Tim Sep 19 '12 at 5:35
    
@Tim, no, that's not possible at this moment, infomration won't update unless you do updatedb again. –  warl0ck Sep 19 '12 at 5:56
    
@Tim updatedb generate a static db file –  warl0ck Sep 19 '12 at 5:56
    
But on my Ubuntu 12.04, the database is updated automatically and periodically. –  Tim Sep 19 '12 at 6:00
    
@Tim yes, there's a cron job that does updatedb daily –  warl0ck Sep 19 '12 at 6:08
add comment

Your Answer

 
discard

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.