您将如何在Bash中执行几行代码来完成以下工作。我正在努力提高我的Bash技能,并学习如何从命令行处理更多的小任务目录。
步骤:
发布于 2017-11-18 04:59:21
您可以将输入日期转换为Unix时间戳,然后添加每天的秒数,并touch
一个以结果命名的文件,直到超过结束日期为止:
#!/bin/bash
startstamp=$(date -d "$1" +'%s')
endstamp=$(date -d "$2" +'%s')
secs_per_day=$(( 24 * 3600 ))
for (( thedate = startstamp; thedate <= endstamp; thedate += secs_per_day )); do
touch "$(date -d "@$thedate" '+%F.w')"
done
%s
格式字符串( GNU扩展)打印自Unix时代以来的秒数,-d
选项的参数中的@
表示日期是该格式的。%F
是%Y-%m-%d
的缩写,意思是YYYY DD.
示例用法:
$ ./dates 2017-11-10 2017-11-15
$ ls -1
2017-11-10.w
2017-11-11.w
2017-11-12.w
2017-11-13.w
2017-11-14.w
2017-11-15.w
dates
https://stackoverflow.com/questions/47361257
复制相似问题