When you install Ubuntu on a dual boot, using the locate command may not show results for your Ubuntu installation. Or worse yet, it might return many results from your host machine. Let’s fix that.
Locate uses an mlocate database to return results for the search. Normally this is updated by cron so you don’t have to fix it, but if you are here, then that cron hasn’t run yet! We can force it to run with a simple command:
1 | sudo updatedb |
sudo updatedb
This may take a while. Be patient.
When you run a locate search now, you should see your Ubuntu files turn up in search. Great! In my case I also had a lot of development files on my Windows 7 installation. I didn’t want those to turn up in my results.
In my case, locate php.ini would return this:
1 2 | /host/xampp/php/php.ini /usr/share/php5/php.ini |
/host/xampp/php/php.ini /usr/share/php5/php.ini
We just have to tell the configuration file to prune the /host/ path. Easy enough:
1 | sudo gedit /etc/updatedb.conf |
sudo gedit /etc/updatedb.conf
Where you see “PRUNEPATHS=”” you will want to add the path to your host machine. In my case:
1 2 3 4 | PRUNE_BIND_MOUNTS="yes" # PRUNENAMES=".git .bzr .hg .svn" PRUNEPATHS="/tmp /var/spool /media /host" PRUNEFS="NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs" |
PRUNE_BIND_MOUNTS="yes" # PRUNENAMES=".git .bzr .hg .svn" PRUNEPATHS="/tmp /var/spool /media /host" PRUNEFS="NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf fuse.glusterfs fuse.sshfs ecryptfs fusesmb devtmpfs"
..and there you go. Happy locating!