Take the 2-minute tour ×

I am trying to find all the files whose name contains exactly 14 digits (I'm trying to match a timestamp in the filename). I'm not sure how to get the GNU find regexp syntax for repetitions right.

I've tried find -regex ".*[0-9]{14} and find -regex ".*[0-9]\{14\}, neither of these turns up any results. Can you help me with the syntax?

share|improve this question
What are you matching them against? –  NullUserException Aug 30 '11 at 14:59
The top answer here by Susam Pal worked for me: stackoverflow.com/questions/6844785/… –  user419153 Jun 9 '12 at 7:18
add comment

3 Answers

up vote 1 down vote accepted

remember, GNU find's -regex matches a whole path. Anyway, you can use a combination of find and grep to do the task, eg to find exactly 14 digits with no other characters

find . -type f -printf "%f\n" | grep -E "\b[0-9]{14}\b"

modify to suit your needs

share|improve this answer
add comment

Strange, I just gave it a try and I could not get this work. Here's a workaround anyway (matching 2 consecutive numbers):

a123.txt  a1b2c3.txt  a45.txt  b123.txt
$find -regex '.*[^0-9][0-9][0-9][^0-9].*'
share|improve this answer
add comment

Try changing the -regextype parameter to find.

Changes the regular expression syntax understood by -regex and -iregex tests which occur later on the command line. Currently-implemented types are emacs (this is the default), posix-awk, posix-basic, posix-egrep and posix-extended.

share|improve this answer
add comment

Your Answer


