简体   繁体   中英

How to list out specific files with dates in the file name in unix shell

I apologize if I'm asking a duplicate question. My google skills have temporarily left me and I don't know how to word my question to find an answer.

I'm working on a unix server and I have a bunch of files with this format as the file name:

alert_YYYY-MM-DD.tsv

I'm trying to list out a specific range of files according to date but for some reason, it's not working how I need it to work.

This works for some reason:

$ ls alert_2015-08-0[1-9].tsv
alert_2015-08-01.tsv  alert_2015-08-04.tsv  alert_2015-08-07.tsv
alert_2015-08-02.tsv  alert_2015-08-05.tsv  alert_2015-08-08.tsv
alert_2015-08-03.tsv  alert_2015-08-06.tsv  alert_2015-08-09.tsv

But this does not, even though the files are present:

$ ls alert_2015-08-[10-15].tsv
ls: alert_2015-08-[10-15].tsv: No such file or directory
$ ls alert_2015-08-1[0-5].tsv   ### but the files exist in the directory!!
alert_2015-08-10.tsv  alert_2015-08-12.tsv
alert_2015-08-11.tsv  alert_2015-08-14.tsv

I'm also trying to span from the single digits to the teens or teens to 20s but it also isn't working, although, it might be more difficult than above:

e.g. 
$ ls alert_2015-08-[09-15].tsv
ls: alert_2015-08-[09-15].tsv: No such file or directory

I'm not sure if this is a glob question or regex question but it's very annoying since logically what I wrote above should work but it doesn't and I don't understand why, other than I have the syntax wrong. Thanks in advance for any help.

the number in [] should be at most 0-9.

$ ls alert_2015-08-[0-1][0-9].tsv
alert_2015-08-01.tsv    alert_2015-08-10.tsv    alert_2015-08-14.tsv
alert_2015-08-04.tsv    alert_2015-08-11.tsv
alert_2015-08-07.tsv    alert_2015-08-12.tsv

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM