Search code examples
regexfind

repetition in GNU find regexp


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?


Solution

  • 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