history:查看历史命令
选项:
n 表示查看最近操作的n个命令
-c 将history中的命令清空
-a 将最新操作的命令新增入historyfiles中
-w 写入~bash_history
每当我们登录下系统后,都会读取用户家目录下的~.bash_history读取曾经使用过的命令。
退出当前用户时会写入~.bash_history中
当root在多个shell登录,最后一个注销的shell才会更新~.bash_history,会覆盖的~~~
[root@www ~]# history 3 1144 cd 1145 vim test.txt 1146 history 3 [root@www ~]# [root@www ~]# tail -3 /root/.bash_history #无最近的命令哦~~ vim /etc/selinux/config getenforce setenforce 0 [root@www ~]# history -w #立刻写入~.bash_history [root@www ~]# tail -3 /root/.bash_history :q tail -3 /root/.bash_history history -w
但是没有记录时间,可以使用~/.bash_logout来记录history的记录。加上date命令。