根据时间和日期显示命令历史记录

时间:2011-08-08 05:12:02

标签: unix

是否可以显示(或设置显示)命令“history”的格式以包含日期?默认情况下,格式为编号,时间和命令。

我的目的是根据时间和日期获取/查找/显示命令,而现在它只有时间。 感谢。

1 个答案:

答案 0 :(得分:1)

http://www.cyberciti.biz/faq/unix-linux-bash-history-display-date-time/ - 这解释了。

基本上,

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

在发出上述命令之前

1995  cd
1996  pwd
1997  history 
1998  echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile
1999  exit
2000  history
2001  cd
2002  pwd
2003  grep
2004  history

之后:

 1995  07/08/11 22:39:33 cd
 1996  07/08/11 22:39:33 pwd
 1997  07/08/11 22:39:33 history 
 1998  07/08/11 22:39:33 echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile
 1999  07/08/11 22:39:33 exit
 2000  07/08/11 22:39:43 history
 2001  07/08/11 22:39:45 cd
 2002  07/08/11 22:39:46 pwd
 2003  07/08/11 22:39:50 grep
 2004  07/08/11 22:39:53 history