- 论坛徽章:
- 0
|
Date 命令参数小技巧
LastUpdated:2006-03-27
By:Gman!
-for beginner:wink:
此参数可以用于日志处理和时间统计;
由于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很详细;我就不一一举例了; |
|