Locate command in Linux read the result from database prepared by updatedb. Locate command picks up the search result based on /var/lib/mlocate/mlocate.db database. This database gets updated daily using cron which is present at /etc/cron.daily/mlocate.cron
If suppose you want to restrict locate command from listing any search result then please make the below changes in updatedb configuration file i.e /etc/updatedb.conf .
Following is the output of my /etc/updatedb.conf file.
[root@afzalkhan ~]# cat /etc/updatedb.conf
PRUNEFS = “auto afs gfs gfs2 iso9660 sfs udf”
PRUNEPATHS = “/afs /media /net /sfs /tmp /udev /var/spool/cups /var/spool/squid /var/tmp”
[root@afzalkhan ~]#
In this output you can see two configuration parameters i.e PRUNEFS & PRUNEPATHS in this configuration file. Lets discuss briefly about this options.
PRUNEFS = A whitespace-separated list of file system types which should not be scanned by updatedb.
PRUNEPATHS = A whitespace-separated list of file directories which should not be scanned by updatedb.
To restrict locate command to list out any search result of locate command just put “/” in PRUNEPATHS list. After modify configuration file looks like :-
[root@afzalkhan ~]# cat /etc/updatedb.conf
PRUNEFS = “auto afs gfs gfs2 iso9660 sfs udf”
PRUNEPATHS = “/afs /media /net /sfs /tmp /udev /var/spool/cups /var/spool/squid /var/tmp /“
[root@afzalkhan ~]#
After updating this configuration file make sure to run “updatedb” command to update the database as per modified configuration file.
[root@afzalkhan ~]# updatedb
Before :-
[root@afzalkhan ~]# locate resolv.conf
/etc/resolv.conf
/etc/sysconfig/networking/profiles/default/resolv.conf
/usr/share/man/man5/resolv.conf.5.gz
[root@afzalkhan ~]#
After :-
[root@afzalkhan ~]# locate resolv.conf
[root@afzalkhan ~]#