Search code examples
regexbashcygwin

Using regex or something else for searching for a file extension


I have to create a bash script that will search a given directory for certain file extensions. The file extensions are in the form of .210 .110 .311 .211 and so on. I cannot do a mere ".2 because there are file names that have that in the name. Is there a way to set a buffer after the ".2" so that the extension is only 3 characters in length? This will remove all the incorrect results from the search.

Right now I am using find /cygdrive/x/Clients -name '*.210'

Thanks!


Solution

  • You should be able to use wildcards. For all files with a 3-digit numeric extension, the following should suffice.

    ls *.[0-9][0-9][0-9] 
    

    If you want only extensions that begin with the number 2, try this:

    ls *.2[0-9][0-9]