0

I've files in a folder like

file_2017-01-01.jpg    
file_2017-02-20.jpg    
file_2017-05-10.jpg    
file_2017-09-01-jpg    
file_2017-10-25.jpg    
file_2017-11-04.jpg    
file_2017-12-22.jpg

How can I use the find command to list files from file_2017-01* to file_2017-10* ?

find . -regextype posix-awk -regex ".*2017-[01-10]*" doesn't work.

Also not, find . -maxdepth 1 -type f -name "*2017-[01-10]*"

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • `[x-y]` is a character class. It matches only one character at a time. – Charles Duffy Nov 28 '17 at 20:29
  • and btw, this isn't a bash question -- the `find` command (at least, the version that supports `-regextype`) is part of GNU `findutils`, which is a completely separate and unrelated package from bash. – Charles Duffy Nov 28 '17 at 20:30

1 Answers1

0

A character class only matches one character at a time, so on its own, it's not an adequate tool for the job in question. Consider instead:

find  . -regextype posix-awk -regex '.*_2017-(0[1-9]|10)-.*' -print

This has two branches: 0[1-9], matching any two-character string from 01 through 09; and 10, matching only the exact string 10.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • ...btw, I'll flag this community-wiki as soon as the question gets its dupe flag set. (Removing the bash tag deactivated my dupehammer... oops!) – Charles Duffy Nov 28 '17 at 20:37