我们执行过的命令 Linux 都会记录,预设可以记录 1000 条历史命令。这些命令保存在用户的家目录的 .bash_history 文件中。但需要注意的是,只有当用户正常退出当前 shell 时,在当前 shell 中运行的命令才会保存至 .bash_history 文件中
查看 history
[root@evan-01 ~]# ls /root/.bash_history
[root@evan-01 ~]# cat /root/.bash_history
...(省略很多内容)
./configure --prefix=/usr/local/apache2.2
echo $?
make
echo $?
make install
echo $?
ls /usr/local/src/
ls /usr/local/apache2.2/
cd /usr/local/apache2.2/
ls
init 0
[root@evan-01 ~]#
查看存了多少条记录
[root@evan-01 ~]# history
...(省略很多内容)
989 ./configure --prefix=/usr/local/apache2.2
990 echo $?
991 make
992 echo $?
993 make install
994 echo $?
995 ls /usr/local/src/
996 ls /usr/local/apache2.2/
997 cd /usr/local/apache2.2/
998 ls
999 init 0
1000 ls /root/.bash_history
1001 cat /root/.bash_history
1002 history
[root@evan-01 ~]#
但是为什么我现在执行 history 后可以出现大于1000多条记录。可以这样理解:
1、如果你不注销或者关机,那么执行hisotry命令,可能记录大于1000,但不会被写入到 .bash_history
2、如果你注销了以后,.bash_history只保存最近的1000条记录
变量 HISTSIZE
[root@evan-01 ~]# echo $HISTSIZE
1000
[root@evan-01 ~]#
修改变量 HISTSIZE 值
[root@evan-01 ~]# vim /etc/profile
按 i 切换编辑模式,/HISTSIZE 搜索到 HISTSIZE=1000,更改 HISTSIZE=1000 为 HISTSIZE=5000。按 esc 键,输入 :wq 保存退出
查看大小
[root@evan-01 ~]# echo $HISTSIZE
1000
[root@evan-01 ~]#
发现还没有更改过来。source 一下