My Samsung Galaxy S doesn't like files where the name contains a long string after the first dot. I guess some part of the software has a too short buffer for the file extension. How can I find all files on my Micro-SD-Card mounted at /media/sd where the filename has more than five characters after the first dot?

Reading the find manpage, I thought

find . -regex '.*\..\{5,\}'

would work, but it doesn't give any hits, so I somehow don't get my regular expression right.


The problem is that the default type of regex's used by find is emacs-style. Find's documentation for emacs style regexes doesn't include the \{n,\} construction--leading me to believe that it isn't supported in find's implemenation of emacs-style regular expressions. The emacs-wiki lists this as valid, however it is possible that this wasn't always the case.

I found that your regex produced output if you do this:

$ find . -regextype posix-basic -regex '.*\..\{5,\}'
  • Yes, this indeed works. As an Emacs user who knows the \{\} syntax, I didn't bother to look up finds emacs regex syntax as I assumed it would be the same. Shame on me for being so full of trust for GNU :-) – fschmitt Nov 17 '10 at 22:27

Braces are not always included in basic regexp implementations. I don't know if you have GNU find or Busybox find; Busybox may not have all the features of GNU find.

A portable way to search for files with a long extension is find . -name '*.?????*'.

Note that your regexp would match most files under a directory whose name contains a dot.

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.