lxy777 发表于 2019-2-17 12:03:17

linux之history命令

  history:查看历史命令

  选项:

  n 表示查看最近操作的n个命令
  -c 将history中的命令清空

  -a 将最新操作的命令新增入historyfiles中

  -w 写入~bash_history
  每当我们登录下系统后,都会读取用户家目录下的~.bash_history读取曾经使用过的命令。

  退出当前用户时会写入~.bash_history中
  当root在多个shell登录,最后一个注销的shell才会更新~.bash_history,会覆盖的~~~

# history 3
1144cd
1145vim test.txt
1146history 3
#
# tail -3 /root/.bash_history      #无最近的命令哦~~
vim /etc/selinux/config
getenforce
setenforce 0
# history -w                #立刻写入~.bash_history
# tail -3 /root/.bash_history
:q
tail -3 /root/.bash_history
history -w  但是没有记录时间,可以使用~/.bash_logout来记录history的记录。加上date命令。



页: [1]
查看完整版本: linux之history命令