I have a bunch js and css files in a directory. Some of them have been given a name based on an md5() of their content (looks like f10521a21bb013cb81e0909809818ad6.js). I'd like to match these files using find. Why does this return 0 results?

find -regex "^[A-f0-9]{32}\.(?:js|css)$"
  • Instead of A-f, I guess you either mean a-f, or A-Fa-f. – user unknown May 4 '12 at 19:50
  • The regular expression is matched against the path, not just the file name, so do not anchor it to the beginning of string.
  • The default emacs type regular expression seems to not like intervals. Choose another.
  • Neither the other regular expression types seem to like the non capturing groups.

These work, supposing you are using GNU find:

find . -regextype posix-awk -regex ".*/[a-f0-9]{32}\.(js|css)$"

find . -regextype posix-basic -regex ".*/[a-f0-9]\{32\}\.\(js\|css\)$"

find . -regextype posix-egrep -regex ".*/[a-f0-9]{32}\.(js|css)$"

find . -regextype posix-extended -regex "/[a-f0-9]{32}\.(js|css)$"

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.