4

I am practicing a find command and the moment, and am curious about the usage of regular expressions in the find command(similar to grep). Does the command support it? If so, what are the options to enable it?

I tried looking for it in the man pages but was unsuccessful so far.

10

From man find:

-regex pattern
              File  name  matches regular expression pattern.  This is a match
              on the whole path, not a search.  For example, to match  a  file
              named `./fubar3', you can use the regular expression `.*bar.' or
              `.*b.*3', but not `f.*r3'.  The regular  expressions  understood
              by  find  are by default Emacs Regular Expressions, but this can
              be changed with the -regextype option.
  • Hi. Thanks for the answer. I saw that option, but being new to Linux, I don't understand if the regular expressions here should be used like in grep (ex. ^[a-z]*\.txt$) or simply as in a shell(ex. ls rando*m?text.txt) – Alex.Kh Oct 3 at 23:17
  • 3
    @Alex.Kh shell metacharacters are different from regular expressions - see the answer at Why does my regular expression work in X but not in Y? – steeldriver Oct 3 at 23:25
  • @steeldriver Oh Wow, that's actually a very nice answer about the difference between globs, regular expressions and extended regular expressions. I thought about asking something like that in the future, but I guess there's no need anymore. Thanks! – Alex.Kh Oct 3 at 23:28
  • @Alex.Kh if you want to dive even deeper, take a look at www.regular-expressions.info – steeldriver Oct 3 at 23:31
  • @steeldriver I will definitely look at the website. Just tell me please, does bash support everything that is mentioned there? – Alex.Kh Oct 4 at 2:24

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.