When I try to search using locate and grep something like:

locate A-B | grep .dir

The result is:


How to modify grep or locate to make the search finished with .dir and nothing more?

I have quite old system:

Secure Locate 2.7 - Released January 24, 2003

grep (GNU grep) 2.5.1


If this is a Linux system, then chances are that you locate supports regular expressions:

locate --regex 'A-B.*\.dir$'

If not,

locate 'A-B' | grep '\.dir$'

The main point is to anchor the regular expression to the end of the line properly with $.

Note that both of these variations would also find e.g. /some/path/ABBA-Bootlegs/thing.dir.

| improve this answer | |
  • The second option is working. The first results empty line. – XuMuK Mar 23 '18 at 15:38
  • @XuMuK It may be that your locate does not support the --regex flag then (see the manual on your system). – Kusalananda Mar 23 '18 at 15:40
  • according to man locate it should work with regex. – XuMuK Mar 23 '18 at 15:47
  • It's easier with the default wildcards anyway: locate '*A-B*.dir' – Stéphane Chazelas Mar 23 '18 at 16:32
  • @StéphaneChazelas in my case Secure Locate 2.7 - Released January 24, 2003 this is not working. The Linux is too old, but it is impossible to update it. – XuMuK Mar 23 '18 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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