TransWikia.com

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

Ask Different Asked on February 21, 2021

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?

One Answer

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.

Correct answer by nohillside on February 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP