I would like to exclude some Windows folders on an NTFS mount from being indexed by locate. I'm familiar with the PRUNEPATHS syntax in /etc/updatedb.conf. It is a white-space separated list of directory names.

My problem is that I want to exclude directories that contain white space themselves (e.g. Program Files (x86)).

I tried backslash escapes but that didn't work.

  • 1
    Which locate implementation you have? Some locate's updatedb is a shell script. In that case see how it uses PRUNEPATHS, that may lead to a workaround. – manatwork Oct 17 '11 at 8:20
  • I use locate (GNU findutils) 4.4.2. Its updatedb is indeed a shell script (/usr/bin/updatedb.findutils). I'll see what I can do from there. Thanks. – lmichelbacher Oct 17 '11 at 13:41

In updatedb.sh line 175 gives a hint:

PRUNEREGEX=`echo $PRUNEPATHS|sed -e 's,^,\\\(^,' -e 's, ,$\\\)\\\|\\\(^,g' -e 's,$,$\\\),'`

There the $PRUNEPATHS is handled like plain text, the ' ' characters are replaced and no escaping is possible.

To ensure the space survives that line 175, you must denote it without explicitly mentioning it. The best way I know is to use \s, which means a whitespace character:


(That will also include tab and newline characters, but in this case will be fine for you.)

Another way is to set $PRUNEREGEX directly, as updatedb would do in line 175:

PRUNEREGEX='\(^/path/to/Program Files (x86)$\)'

There you separate multiple paths with \|, so space is not an issue anymore:

PRUNEREGEX='\(^/path/to/Program Files (x86)$\)\|\(^/foo/bar$\)'
  • The \s trick works but only with the --prunepaths option of the script not whe put in the conf file. I'll probably make my own PRUNEREGEX. Thanks. – lmichelbacher Oct 17 '11 at 16:35
  • Honestly I only tested it with command line parameter and environment variable. Actually I was unable to find any evidence that updatedb uses /etc/updatedb.conf. – manatwork Oct 17 '11 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.