bash history(history命令)

列出所有的历史记录:#history

只列出最近10条记录:#history 10

bash执行命令时不是马上把命令名称写入.bash_history文件的,而是存放在内部的buffer中,等bash退出时会一并写入。

  不过,可以调用history -w命令要求bash立即更新history文件。

  history -w

内存中记录过往指令数根据环境变量HISTSIZE而定。

.bash_history中的指令数根据环境变量HISTFILESIZE而定。

调往过往指令:

!!:重复执行上一条指令

!a:复执行上一条以a为首的指令

!number:重复执行上一条在history表中记录号码为number的指令

!$:执行上一条命令的最后一条命令去执行

################################################

例如:[root@localhost ~]# ping 192.168.1.100
PING 192.168.1.100 (192.168.1.100) 56(84) bytes of data.

[root@localhost ~]# ping !$
ping 192.168.1.100
PING 192.168.1.100 (192.168.1.100) 56(84) bytes of data.

################################################

history命令的记录如何删除?

修改/etc/profile将HISTSIZE=1000改成0或1

清除用户home路径下.bash_history

立即清空里的history当前历史命令的记录

  history -c

原文地址:https://www.cnblogs.com/feihongwuhen/p/7170491.html