history显示历史操作记录,并显示操作时间

在查看历史的操作记录有两种方式
1.在用户的目录下的.bash_history文件中
[root@node1 ~]# vi ~/.bash_history

reboot
vi /etc/sysconfig/network-scripts/ifcfg-eth0
setup
service netwok restart
service network restart
ping 192.168.11.70
vi /etc/hosts
vi /etc/sysconfig/network
df -h
shutdown -h now
exit
su - highgo
service iptables stop
shutdown -h now

2.直接执行history命令
[root@node1 ~]# history
1 ll
2 rm -rf pgpool*
3 ll
4 tar -xvf postgresql-9.4.4.tar.gz
5 mkdir pgsql-9.4
6 mkdir -p pgsql/data
7 cls
8 ls
9 cd postgresql-9.4.4
10 ./configure --prefix=/opt/pgsql-9.4/
11 make
12 make clean
这两种方式虽然能看到执行的命令,但是不能看出执行的时间,我们进行以下操作,让history能显示执行的时间
编辑/etc/bashrc文件,添加以下四行:
HISTFILESIZE=2000
HISTSIZE=2000
HISTTIMEFORMAT='%F %T '
export HISTTIMEFORMAT


[root@node1 ~]# vi /etc/bashrc
[root@node1 ~]# source /etc/bashrc
[root@node1 ~]# history
999 2017-03-23 16:14:29 shutdown -h now
1000 2017-03-23 16:14:34 history
1001 2017-03-23 16:21:56 vi /etc/bashrc
1002 2017-03-23 16:22:29 source /etc/bashrc
1003 2017-03-23 16:22:32 history

注:HISTFILESIZE定义了.bash_history中保存命令的总数,默认是1000,这里改成了2000,HISTSIZE设置了history命令输出最多的记录总数,
HISTTIMEFORMAT定了时间显示格式。

有可能会出现以前的操作记录都会显示更改/etc/bashrc 文件的时间,而不是真正的操作时间,只有更改完/etc/bashrc以后的操作记录会显示正确的时间

原文地址:https://www.cnblogs.com/z-x-y/p/9507283.html