tested on: Linux 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt7-1 (2015-03-01) x86_64 GNU/Linux
If you are under linux, you probably know find.
I hate find.
It’s slow and it seldom returns what i need.
Locate is much quicker, rerun by cron daily to index new files, but how the heck do i add my external NAS to that updatedb-database for faster search?
# you can locate the database
# and have a look at it via
# this is where the update db config is located
# mine reads like
PRUNE_BIND_MOUNTS="yes" # ignore all mounts? (NFS, SMB etc.)
# PRUNENAMES=".git .bzr .hg .svn" # do not index-scan dirs/files with that names
PRUNEPATHS="/tmp /var/spool /media" # do not index-scan those paths
PRUNEFS="rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre tmpfs usbfs udf fuse.glusterfs fuse.sshfs curlftpfs"
# PRUNEFS="NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre tmpfs usbfs udf fuse.glusterfs fuse.sshfs curlftpfs"
how is my NAS mounted?
mount; # display all mounted devices ... 192.168.1.123:/DATA on /mnt/DATA type nfs (rw,relatime,vers=3,rsize=32768,wsize=32768,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=192.168.1.123,mountvers=3,mountport=44010,mountproto=udp,local_lock=none,addr=192.168.1.123)
so the answer is:
1. i need to remove NFS and nfs from PRUNEFS
2. i need to set
3. rerund updatedb
sudo updatedb -v; # rerun updatedb, watch it work while it indexes my NAS as well :-)
4. updatedb is in cron.daily and probably starts as soon as the system is powered on… the NAS takes longer to power on, so i moved
mv /etc/cron.daily/mlocate /etc/cron.daily/cron.weekly/
which is okay for me… don’t need daily indexing of the HD.
if that is still not working for you try this:
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.