讓linuxhistory命令顯示命令的執行時間、在哪個機器執行的這個命令

來源:互聯網
上載者:User

讓linuxhistory命令顯示命令的執行時間、在哪個機器執行的這個命令

1.在/etc/profile的最後添加如下部分:
USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'` export HISTTIMEFORMAT="[%F %T][`whoami`][${USER_IP}] "
2. source /etc/profile
3.隨便執行一下什麼命令,
4.執行history,看效果: 311 [2013-08-28 14:39:20][root][192.168.80.1] history 312 [2013-08-28 14:39:43][root][192.168.80.1] df -h 313 [2013-08-28 14:39:45][root][192.168.80.1] df -g 314 [2013-08-28 14:39:47][root][192.168.80.1] history 315 [2013-08-28 14:40:01][root][192.168.80.1] ifconfig 316 [2013-08-28 14:44:53][root][192.168.80.1] init 6 317 [2013-08-28 14:46:56][root][192.168.80.1] sdfsdfsd 318 [2013-08-28 14:46:58][root][192.168.80.1] ls 319 [2013-08-28 14:47:02][root][192.168.80.1] hostory 320 [2013-08-28 14:47:04][root][192.168.80.1] history 321 [2013-08-28 14:48:35][root][192.168.80.1] cat /etc/profile 322 [2013-08-28 14:54:32][root][192.168.80.1] history
注意:1和2必須先執行完之後,才能看到history的效果。若是想看1個月前的history,而那時還沒有執行1和2,這種情況下是看不到想要的效果的。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.