文章出處

解決CentOS 7 history命令不顯示操作記錄的時間和用戶身份問題。
centos6 中history命令顯示操作命令的時間和用戶身份

[root@node02~]#history2942017-01-0616:46:48rootclear2952017-01-0616:46:50rootll2962017-01-0616:46:52rootcathostname.sh2972017-01-0616:46:56rootcatnginxlog_cut.sh2982017-01-0616:47:29rootclear2992017-01-0616:47:34roothistory[root@node02~]#cat/etc/redhat-releaseCentOSrelease6.6(Final)[root@node02~]#

而centos7中,history命令中不顯示操作命令的時間和用戶身份

[root@localhostdata]#cat/etc/redhat-releaseCentOSLinuxrelease7.2.1511(Core)[root@localhostdata]#history-n10[root@localhostdata]#history101268\1269history1270cat/etc/redhat-release1271clear1272cat/etc/redhat-release1273history1274clear1275cat/etc/redhat-release1276history-n101277history10[root@localhostdata]#

解決該問題只需要在/etc/profile中添加如下變量即可:

export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S `whoami` "

然后運行source /etc/profile命令即可,注意引號中的空格

[root@localhostdata]#history1012732017-01-0519:40:18roothistory12742017-01-0519:40:27rootclear12752017-01-0519:40:29rootcat/etc/redhat-release12762017-01-0519:40:35roothistory-n1012772017-01-0519:40:39roothistory1012782017-01-0519:41:12rootcat/etc/profile12792017-01-0519:42:16rootvim/etc/profile12802017-01-0519:42:26rootsource/etc/profile12812017-01-0519:42:28roothistory12822017-01-0519:42:42roothistory10[root@localhostdata]#

至此history命令輸出結果格式完美解決,如果要清除歷史記錄,可以運用history -c,具體history用法如下:

history命令的用法及參數usage: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]

參數:

n :數字,要列出最近的若干命令列表

-c :將目前的 shell 中的所有 history 內容全部消除

-a :將目前新增的 history 指令新增入 histfiles 中,若沒有加 histfiles ,則預設寫入 ~/.bash_history

-r :將 histfiles 的內容讀到目前這個 shell 的 history 記憶中

-w :將目前的 history 記憶內容寫入 histfiles

看文倉www.kanwencang.com網友整理上傳,為您提供最全的知識大全,期待您的分享,轉載請注明出處。
歡迎轉載:http://www.kanwencang.com/bangong/20170110/84311.html

文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


全站熱搜
創作者介紹
創作者 大師兄 的頭像
大師兄

IT工程師數位筆記本

大師兄 發表在 痞客邦 留言(0) 人氣()