知乎专栏 |
从安全角度考虑禁止记录history
ln -s /dev/null .bash_history
定制.bash_history格式
export HISTSIZE=1000 export HISTFILESIZE=2000 export HISTTIMEFORMAT="%Y-%m-%d-%H:%M:%S " export HISTFILE="~/.bash_history"
看看实际效果
$ 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 |
# history -cw
清楚指定行
# history -d 5
临时关闭历史记录
# 关闭 # set +o history # 恢复 # set -o 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