小编had*_*des的帖子

使用文件名 date 指定特定日期范围内的 Linux tar 文件

我的文件名称以 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)

我应该匹配什么模式?

linux shell date globbing

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

date ×1

globbing ×1

linux ×1

shell ×1