Bash – Searching a pattern in file names with number

bashdatewildcardszsh

I have a large number of files in a folder each with the date as the filename.
For example

20130101
20130102
20130103
.
.
.
20130131

similarly for other months 20130201 to 20130230, the pattern is [Year][Month][Day].
I need to make a tar file of the first fifteen files from JAN to APRIL
(i.e 2013[01-04][01-15]), since double digit number range is not allowed in grep. How should I search this pattern?

Best Answer

With zsh:

tar zcf ~/file.tar.gz 20130<1-4><1-15>

If you have to use bash:

shopt -s extglob
tar zcf ~/file.tar.gz 20130[1-4]@(0?|1[0-5])
Related Question