Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

locate "*.png" returns all files ending with .png, as expected.

locate "test.*" doesn't return anything, but there are files named test in my system.

locate "*test" returns all files ending with test, as expected.

locate "test*" doesn't return anything, but there are files starting with test in my system.

Why do wildcards seem to work only for "ending with"?

share|improve this question
1  
Did you rebuild the locatedb after creating the files that match test* and test.*? –  Ignacio Vazquez-Abrams Jun 29 '13 at 10:34
    
@IgnacioVazquez-Abrams: yes –  Vittorio Romeo Jun 29 '13 at 10:44

1 Answer 1

up vote 3 down vote accepted

locate "test.*" doesn't return anything, but there are files named test in my system.

. is treated as dot, not as in regex's as an arbitrary character, so test.* does not match test, but test.foo.

locate "test*" doesn't return anything, but there are files starting with test in my system.

locate stores the full path to the file, so to find files starting with test, you should use locate "*/test*".

The last point might be confusing, as locate foo finds anything including foo, so the pattern gets interpreted as *foo*. It seems that the pattern is not enclosed in stars, if there is already one wildcard in the pattern.

Disclaimer: I did some test and these are my conclusions, I cannot prove them by citing the man page, which seems very rudimentary.

share|improve this answer
    
Thanks, it makes sense now. –  Vittorio Romeo Jun 29 '13 at 11:28
2  
In my man locate I have: If --regex is not specified, PATTERNs can contain globbing characters. If any PATTERN contains no globbing characters, locate behaves as if the pattern were *PATTERN*. –  gniourf_gniourf Jun 30 '13 at 10:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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