Skip to content

Exclude some paths for locate command in Ubuntu

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

  1. Open the updatedb configuration file:sudo vi /etc/updatedb.conf
  2. 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"
  3. Save and close the file .
  4. 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.

Leave a Reply