码迷,mamicode.com
首页 > 系统相关 > 详细

shell中获取时间,作为目录格式

时间:2014-10-12 02:22:57      阅读:313      评论:0      收藏:0      [点我收藏+]

标签:shell   时间   

最近写了一个小程序,需要用到时间,遍历作为目录的一部分

#!/bin/bash
for i in {1..30}
do
date=`date +%Y/%m/%d -d " $i days ago " `
echo $date
done

for循环,取最近n天的日期。

核心就是

date=`date +%Y/%m/%d -d " $i days ago " `

结果, 你可以拼在目录后面:

2014/10/10
2014/10/09
2014/10/08
2014/10/07
2014/10/06
2014/10/05
2014/10/04
2014/10/03
2014/10/02
2014/10/01
2014/09/30
2014/09/29
2014/09/28
2014/09/27
2014/09/26
2014/09/25
2014/09/24
2014/09/23
2014/09/22
2014/09/21
2014/09/20
2014/09/19
2014/09/18
2014/09/17
2014/09/16
2014/09/15
2014/09/14
2014/09/13
2014/09/12
2014/09/11




shell中获取时间,作为目录格式

标签:shell   时间   

原文地址:http://blog.csdn.net/smile0198/article/details/40004113

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!