新聞中心
Linux系統(tǒng)使用History命令來(lái)查看系統(tǒng)的運(yùn)行記錄,從而找出一些問(wèn)題。但是History輸出的數(shù)據(jù)中常常沒(méi)有時(shí)間等信息。本文就來(lái)教大家Linux系統(tǒng)如何定制History輸出格式。

網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)建站!專注于網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、微信小程序開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了田東免費(fèi)建站歡迎大家使用!
具體方法如下
以root用戶登錄服務(wù)器,在/etc/profile.d/下新建一個(gè)文件history_command
vim /etc/profile.c/history_command
export HISTFILE=$HOME/.bash_history
export HISTSIZE=1200
export HISTFILESIZE=1200
export HISTCONTROL=ignoredups
export HISTTIMEFORMAT=“`whoami` %F %T ”
shopt -s histappend
typeset -r HISTTIMEFORMAT
source /etc/profile.c/history_command 使其生效,再敲history命令看看:
#history 5
1008 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
時(shí)間已經(jīng)有了,/etc/profile和/etc/profile.d/下的文件會(huì)在用戶interactive login的時(shí)候自動(dòng)執(zhí)行,所以用戶登錄機(jī)器后每敲一個(gè)命令都會(huì)被記錄到HISTFILE指定的文件中,而且是以追加的方式寫入的。
配置中最關(guān)鍵的地方是export HISTTIMEFORMAT=“whoami %F %T ” , 這一行指定history的輸出格式。
當(dāng)前文章:Linux下定制History命令輸出格式
轉(zhuǎn)載來(lái)源:http://www.dlmjj.cn/article/codigpc.html


咨詢
建站咨詢
