[Linux技巧] 让date命令的输出格式符合你的习惯

写着代码,想知道时间(或者日期,看你的想法),Linux中有个很好的命令:date。

Have a try...

unimous@unimous-f41:~$ date
Sun Feb 26 22:39:43 CST 2012

 So strange... 可能我们都很不习惯看这种默认的“星期、月、日、时间”,还加个“CST”(美国中部标准时间?为什么?)、然后“年”的格式,我希望这样:时间,然后日期,然后星期,help一下:

unimous@unimous-f41:~$ date --help
Usage: date [OPTION]... [+FORMAT]
or: date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
Display the current time in the given FORMAT, or set the system date.
...

%% a literal %
%a locale's abbreviated weekday name (e.g., Sun)
%A locale's full weekday name (e.g., Sunday)
...
%F full date; same as %Y-%m-%d
...
%R 24-hour hour and minute; same as %H:%M
...

注意到[+FORMAT],然后重新尝试:

unimous@unimous-f41:~$ date +"%R %F %A"  
22:50 2012-02-26 Sunday

这样不错了,但是 如果每次查询时间都要敲这么长串命令显得麻烦,故可在启动脚本~/.brshrc中加入一行别名,如下:

alias date='date +"%R  %F %A"'

[DONE]

posted @ 2012-02-26 23:01  UniMouS  阅读(2929)  评论(0编辑  收藏  举报

版权所有 © 2011-2012 方一曙

Copyright © 2011-2012 Fang Yishu (UniMouS)