11

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"?

2
  • 1
    Did you rebuild the locatedb after creating the files that match test* and test.*? Jun 29, 2013 at 10:34
  • @IgnacioVazquez-Abrams: yes Jun 29, 2013 at 10:44

1 Answer 1

16

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.

1
  • 4
    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*. Jun 30, 2013 at 10:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .