1. 程式人生 > >Linux系統如何定製History輸出格式

Linux系統如何定製History輸出格式

Linux系統使用History命令來檢視系統的執行記錄,從而找出一些問題。但是History輸出的資料中常常沒有時間等資訊。本文就來教大家Linux系統如何定製History輸出格式。

Linux系統如何定製History輸出格式Linux系統如何定製History輸出格式

  具體方法如下

以root使用者登入伺服器,在/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

時間已經有了,/etc/profile和/etc/profile.d/下的檔案會在使用者interactive login的時候自動執行,所以使用者登入機器後每敲一個命令都會被記錄到HISTFILE指定的檔案中,而且是以追加的方式寫入的。

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

以上就是Linux系統如何定製History輸出格式的介紹了,這樣就能讓History顯示更多自己想要知道的資訊了。