Files from your external harddisk are not indexed because updatedb
is configured to not index anything under /media
, which is where external storage is usually mounted. This configuration is set in the file /etc/updatedb.conf
. Specifically the entry /media
in the PRUNEPATHS
line.
Some ideas how you can make updatedb
to index your external drive:
1. Mount the external drive unter /mnt
.
If your external harddisk is supposed to be mounted permanently then I suggest to configure it so that it is mounted under /mnt
instead of under /media
. That can usually be done by editing /etc/fstab
. Search for "fstab" to learn about that. You will need sudo rights to edit /etc/fstab
.
2. Create a dedicated database for your external harddisk and query that on demand.
The following command will create a dedicated database:
updatedb -l 0 -o ~/.externalharddisk.db -U /media/externalharddisk
This will create the database in the hidden file .externalharddisk.db
in your home. You do not need sudo
for that command. Execute the same command again to keep the database updated. Carefull: if you run that command while the external harddisk is not mounted then updatedb
will think the files are deleted and will empty the database.
You can set up a script to automate that task. Search for "cronjob" to learn how to do that. Note: you can set up a user cronjob as user. You do not need sudo rights to set up a user cronjob.
The following command will query the database:
locate -d ~/.externalharddisk.db searchterm
You can also query the dedicated database and the default database at the same time:
locate -d ~/.externalharddisk.db: searchterm
The colon at the end followed by nothing means to also search in the default database.
You can make an alias for easier use. Put the following line in your .bashrc
:
alias locate-external='locate -d ~/.externalharddisk.db:'
Now you can use locate
to search only the default database and locate-external
to also search in your external harddisk.
3. Remove /media
from PRUNEPATHS
Note: I do not recommend this! This is because of the way updatedb
works. If updatedb
runs while the external harddisk is removed then all entries pointing to the external harddisk will be removed from the database. If updatedb
runs while the external harddisk is connected then entries pointing to the external harddisk will be added again. Since updatedb
is running regulary in the background you can never be sure whether the files from the external harddisk are currently indexed or not.
Furthermore: if you remove /media
from PRUNEPATHS
, this behaviour will also apply to any other external storage you happen to have mounted while updatedb
is updating the database.
Best Answer
sudo apt-get install mlocate
should install the 'locate' command.mlocate
maintains a database of all your files and is re-indexed once a day by default. If you want it to re-index immediately then runsudo updatedb
from the command line.If you get a
cannot stat
error when you runlocate
, then you need to runsudo updatedb
to populate the database, just as if you wanted to re-index immediately.