Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What am I doing wrong with this find expression?

; touch ook ooks
; find . -name 'ook' -or -name 'ooks' -type f
; find . -name 'ook[s]?' -type f      
[returns nothing]
; echo $?
share|improve this question
up vote 8 down vote accepted

You're confusing regular expressions with shell search patterns.

? in shell means any single character.

? in regexp means the previous character (or sub-pattern) is optional.


find . -regex '.*ooks?' -type f

From the find man page:

       -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.
share|improve this answer

This answer applies at least to GNU find.

-name matches using shell patterns, if you want to do regex matching use -regex instead:

 find . -regex '.*ook[s]?' -type f

-regex matches the whole path using emacs regex. Regular expression type can be changed with -regextype.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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