Home | Mirror | Search

6. History 命令歷史記錄

6.1. .bash_history

ln -s /dev/null .bash_history
			

定製.bash_history格式

HISTSIZE=1000
HISTFILESIZE=2000
HISTTIMEFORMAT="%Y-%m-%d-%H:%M:%S "
export HISTTIMEFORMAT
			

看看實際效果

$ history | head
    1  2012-02-27-09:10:45 do-release-upgrade 
    2  2012-02-27-09:10:45 vim /etc/network/interfaces 
    3  2012-02-27-09:10:45 vi /etc/network/interfaces 
    4  2012-02-27-09:10:45 ping www.163.com
			

提示

CentOS 可以添加到 /etc/bashrc 這樣可以對所有用戶起作用

echo 'export HISTTIMEFORMAT="%Y-%m-%d-%H:%M:%S "' >> /etc/bashrc
				

6.2. .mysql_history

ln -s /dev/null .mysql_history
			

插入時間點,在~/.bashrc中加入下面命令

$ tail ~/.bashrc 
echo `date` >> ~/.mysql_history
			
$ tail ~/.mysql_history 
EXPLAIN SELECT * FROM stuff where id=3 \G
EXPLAIN SELECT * FROM stuff where id='3' \G
EXPLAIN SELECT * FROM stuff where id='2' \G
Mon Feb 27 09:15:18 CST 2012
EXPLAIN SELECT * FROM stuff where id='2' and created = '2012-02-01' \G
EXPLAIN SELECT * FROM stuff where id='1' and created = '2012-02-01' \G
EXPLAIN SELECT * FROM stuff where id='3' and created = '2012-02-01' \G
EXPLAIN SELECT * FROM stuff where id='2' and created = '2012-02-01' \G
EXPLAIN SELECT * FROM stuff where id='2' or created = '2012-02-01' \G
EXPLAIN SELECT * FROM stuff where id='2' and created = '2012-02-01' \G
Mon Feb 27 11:48:37 CST 2012
			
comments powered by Disqus