To exclude certain paths when using the locate
command in Linux, you can modify the updatedb
configuration file to exclude specific directories from being indexed. Here’s how you can do it:
Step-by-Step Guide
- Open the
updatedb
configuration file:sudo vi /etc/updatedb.conf
- Edit the
PRUNEPATHS
variable to include the paths you want to exclude. For example, to exclude/home/user/temp
and/var/log
, modify the line to look like this:PRUNEPATHS="/tmp /var/spool /media /home/user/temp /var/log"
- Save and close the file .
- Update the locate database:
sudo updatedb
Example
If you want to exclude /home/user/temp
and /var/log
directories, your updatedb.conf
file should have the PRUNEPATHS
line like this:
PRUNEPATHS="/tmp /var/spool /media /home/user/temp /var/log"
After updating the database with sudo updatedb
, the locate
command will no longer include files from these directories in its search results.