我正在尝试获取参考文件的以前的日期。
我尝试过的
[rahul@testsrv]$ date +%F -r /tmp/ftpbkp.log
2013-08-27
[rahul@testsrv]$ date +%F -r /tmp/ftpbkp.log -d "1 day ago"
date: the options to specify dates for printing are mutually exclusive
Try `date --help' for more information.
警告说明:
$ date -r ~/a
Sun 28 Oct 23:12:00 GMT 2012
$ LC_ALL=C date -r ~/a
Sun Oct 28 23:12:00 GMT 2012
作为输出,date
以用户的本地格式输出日期。但是,作为对-d
GNU的输入,date
在格式上更加挑剔:
$ date -d "$(date -r ~/a) - 1 day"
date: invalid date ‘Sun 28 Oct 23:12:00 GMT 2012 - 1 day’
将语言环境固定为C可以解决以下问题:
$ export LC_ALL=C
$ date -d "$(date -r ~/a) - 1 day"
Sun Oct 28 00:12:00 BST 2012
但是请注意日期仍然是2012-10-28,尽管现在是夏季时间。那是因为在英国那一天之前24小时,我们仍然是同一天。
现在,如果您需要前一天,则必须编写它:
date -d "$(date -r /tmp/file.ref +'%F -1 day')" +%F
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句