history命令的用法及参数
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
重复执历史特定指令
[root@keystone ~]# history 10 # 列出最后10条执行的命令
[root@keystone ~]# !988 # 执行第988条指令
[root@keystone ~]# !! # 执行最后一条指令
[root@keystone ~]# history -c # 清除所有的指令记录
给history打个时间标签
#1.内置命令history
history -c #清除历史输入的命令
history -w #立即写进历史命令文件中 ~/.bash_history
修改/etc/profile文件
HISTFILESIZE=2000 #保存命令的个数
HISTTIMEFORMAT="%Y%m%d-%H%M `whoami` "
刷新环境变量:source /etc/profile
#2.给history打个时间标签
[root@eyelimit ~]# cat /etc/profile |grep %M
HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S `whoami`"
export HISTTIMEFORMAT
[root@eyelimit ~]# source /etc/profile
[root@eyelimit ~]# history |more
1 2013-03-10 20:08:09 ls
#3.使用 HISTTIMEFORMAT显示时间戳在 /etc/bashrc
TMOUT=300 #连接超时5min,自动退出
HISTSIZE=1000
HISTFILE=/var/log/command_history
HISTTIMEFORMAT='< %F %T > : '
HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S `whoami` "
yum -y install bash-completion
记录历史命令时间戳及remote_ip
/etc/profile
export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S `whoami` "
USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
export HISTTIMEFORMAT="[%F %T][`whoami`][${USER_IP}] "
USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S `whoami` ${USER_IP} "