红联Linux门户
Linux帮助

Date 命令参数小技巧

发布时间:2006-12-09 10:00:45来源:红联作者:wuhu911
-for beginner
此参数可以用于日志处理和时间统计;

由于Linux对man date -d 参数说的比较模糊,故举例如下:
# -d, --date=STRING display time described by STRING, not `now'


For Linux
[root@Gman root]# date -d next-day +%Y%m%d
20060328
[root@Gman root]# date -d last-day +%Y%m%d
20060326
[root@Gman root]# date -d yesterday +%Y%m%d
20060326
[root@Gman root]# date -d tomorrow +%Y%m%d
20060328
[root@Gman root]# date -d last-month +%Y%m
200602
[root@Gman root]# date -d next-month +%Y%m
200604
[root@Gman root]# date -d next-year +%Y
2007

-------------
而FreeBSD则不同;举例如下:

For FreeBSD
bash-2.05b# date -v -1d +%Y%m%d
20060326
bash-2.05b# date -v -1m +%Y%m%d
20060227
bash-2.05b# date -v -1y +%Y%m%d
20050327

FreeBSD 的man date很详细;我就不一一举例了;
文章评论

共有 0 条评论