how can i use regex with locate command in linux


I want to use the locate command with regex but i am not able to use it.

I want to find pip file which is in /usr folder. i am trying this

locate -r "/usr/*pip"


To use globbing characters in your query you shouldn’t specify regex (as you do with -r option), so just do:

locate "/usr/*pip"

From the man page:

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*.

Answered By – Nelson

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published