locate `pre-commit` and not `pre-commit.sample`

I would like to find all files named pre-commit, the problem is that I also find pre-commit.sample.

locate pre-commit.

How can I find the files that don't have the .sample extension?


Solution 1:

locate uses shell-style globbing so the options for the pattern are kind of limited.

The simple way probably is to just run

locate pre-commit | grep -v 'sample$'

Or you could make use of the special case documented in man locate

As a special case, a pattern containing no globbing characters (``foo'') is matched as
though it were ``*foo*''.

and use locate 'pre?commit' (quoting is required to prevent the shell from expanding the pattern) to prevent the automatic adding of the * wildcard.