我的文件名称以 YYYYMMDD 开头,如下所示:
20160221_143223_Report.csv
20160222_121223_Report.csv
...
20160229_141223_Report.csv
20160301_171223_Report.csv
Run Code Online (Sandbox Code Playgroud)
我想要 tar 文件名中包含“Report”且其名称对应于 1-8 天前范围的文件。例如:今天是 3 月 1 日,所以我想 tar 2 月 22 日到 2 月 29 日(不包括今天)的文件。
files=($(ls |<HAS "Report" in filename> and <WITHIN `date -d "8 days ago" '+%Y%m%d'> )) #output will be filenames that has the word "Report" and from 22th to 29th FEB
tar cvfz oldfile.tar.gz "${files[@]}"
Run Code Online (Sandbox Code Playgroud)
我应该匹配什么模式?