`locate` wildcard strange behavior - why?
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 withtest
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.
Related videos on Youtube
Vittorio Romeo
Updated on September 18, 2022Comments
-
Vittorio Romeo over 1 year
locate "*.png"
returns all files ending with.png
, as expected.locate "test.*"
doesn't return anything, but there are files namedtest
in my system.locate "*test"
returns all files ending withtest
, as expected.locate "test*"
doesn't return anything, but there are files starting withtest
in my system.Why do wildcards seem to work only for "ending with"?
-
gniourf_gniourf almost 11 yearsIn 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*.