[Linux] bash在history中加上日期时间戳

博客首页 » Linux bash在history中加上日期时间戳

发布于 09 Jun 2014 00:57
标签 blog
偶尔看到NIXCRAFT写了这么一个经验,对于bash有些作用。
用export HISTTIMEFORMAT="%d/%m/%y %T ",就可以在.bash_history上加上日期时间戳。

http://www.cyberciti.biz/faq/unix-linux-bash-history-display-date-time/

Bash History: Display Date And Time For Each Command
by NIXCRAFT on MARCH 11, 2010 · 28 COMMENTS· LAST UPDATED MARCH 11, 2010
in BASH SHELL

How do I display shell command history with date and time under UNIX or Linux operating systems?

If the HISTTIMEFORMAT is set, the time stamp information associated with each history entry is written to the history file, marked with the history comment character. Defining the environment variable as follows:
$ HISTTIMEFORMAT="%d/%m/%y %T "

OR
$ echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' » ~/.bash_profile

Where,
%d - Day
%m - Month
%y - Year
%T - Time
To see history type
$ history

Sample outputs:

….
..
986 11/03/10 04:31:36 memcached-tool 10.10.28.22:11211 stats
987 11/03/10 04:31:36 w
988 11/03/10 04:31:37 iostat
989 11/03/10 04:31:37 top
990 11/03/10 04:31:37 at
991 11/03/10 04:31:38 atop
992 11/03/10 04:31:40 collectl
993 11/03/10 04:31:41 grep CPU /proc/cpuinfo
994 11/03/10 04:31:45 vmstat 3 100
995 11/03/10 04:31:55 sar -W -f /var/log/sa/sa12
….
..
References:
For more info type the following commands:
man bash
help history
man 3 strftime


本页面的文字允许在知识共享 署名-相同方式共享 3.0协议和GNU自由文档许可证下修改和再使用,仅有一个特殊要求,请用链接方式注明文章引用出处及作者。请协助维护作者合法权益。


系列文章

文章列表

  • Linux bash在history中加上日期时间戳

这篇文章对你有帮助吗,投个票吧?

rating: 0+x

留下你的评论

Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License