Search code examples
regexfilefinddigits

find files using regex with exact digits number


I'm trying to find all files on linux that would match files like these:

frontend_prod_20100112.log
frontend_prod_20110101.log
frontend_prod_20120101.log
frontend_prod_20121231.log

the only variable here is 8 digits inside (exactly 8). I'm trying to run:

find . -regex ".*frontend_prod_[0-9]{8}\.log"

or

find . -regex ".*frontend_prod_(\d){8}\.log"

but it doesn't work.

Thanks for any help.


Solution

  • Since this is POSIX, you need a slightly different syntax:

    find . -regex ".*frontend_prod_[0-9]\{8\}\.log"