本篇内容主要讲解“Linux下如何定制History命令输出格式”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Linux下如何定制History命令输出格式”吧!
具体方法如下
以root用户登录服务器,在/etc/profile.d/下新建一个文件history_command
vim /etc/profile.c/history_commandexport HISTFILE=$HOME/.bash_historyexport HISTSIZE=1200export HISTFILESIZE=1200export HISTCONTROL=ignoredupsexport HISTTIMEFORMAT=“`whoami` %F %T ”shopt -s histappendtypeset -r HISTTIMEFORMAT
source /etc/profile.c/history_command 使其生效,再敲history命令看看:
#history 51008 root 2015-09-11 08:54:20 vim /etc/profile 1009 root 2015-09-11 09:13:17 history | less 1010 root 2015-09-11 09:15:49 vim /etc/profile 1011 root 2015-09-11 09:43:20 cat /etc/profile.d/history_command 1012 root 2015-09-11 09:44:59 history 5
时间已经有了,/etc/profile和/etc/profile.d/下的文件会在用户interactive login的时候自动执行,所以用户登录机器后每敲一个命令都会被记录到HISTFILE指定的文件中,而且是以追加的方式写入的。
配置中最关键的地方是export HISTTIMEFORMAT=“whoami
%F %T ” , 这一行指定history的输出格式。
到此,相信大家对“Linux下如何定制History命令输出格式”有了更深的了解,不妨来实际操作一番吧!这里是本站网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!