溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Linux系統(tǒng)如何定制History輸出格式

發(fā)布時間:2020-08-05 09:57:32 來源:ITPUB博客 閱讀:119 作者:安全劍客 欄目:建站服務(wù)器

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

Linux系統(tǒng)如何定制History輸出格式

  具體方法如下

以root用戶登錄服務(wù)器,在/etc/profile.d/下新建一個文件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

時間已經(jīng)有了,/etc/profile和/etc/profile.d/下的文件會在用戶interactive login的時候自動執(zhí)行,所以用戶登錄機(jī)器后每敲一個命令都會被記錄到HISTFILE指定的文件中,而且是以追加的方式寫入的。

配置中最關(guān)鍵的地方是 export HISTTIMEFORMAT=“`whoami` %F %T ”  , 這一行指定history的輸出格式。

以上就是Linux系統(tǒng)如何定制History輸出格式的介紹了,這樣就能讓History顯示更多自己想要知道的信息了。


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI