Linux命令 history

history

历史查询命令,可以看到之前的执行操作。存储的数量可以由环境变量HISTSIZE控制。

选项:

  n  history 30  显示最近输入的30条命令

  - c : 将当前shell中的所有history信息都删除。

  - r : 将histfiles中的内容添加到 shell 的 history 中

  -w : 将目前的history 内容添加到 histfiles中

  -a : 将目前新增的history加入histfiles中,若没有加histfiles则加入到~/.bash_history

几个实用操作

[root@iZj6c1fa4tkhgpvnd9f12rZ ~]# history 10
  320  echo $$
  321  echo $?
  322  history
  323  ss
  324  alias dir="ls -l"
  325  dir .
  326  unalias dir
  327  dir .
  328  history 30
  329  history 10

  第一列是命令的编号 应该说是第几个吧, 

[root@iZj6c1fa4tkhgpvnd9f12rZ ~]# !325
dir .
demo_test  docker_demo	gpu_env  nvidia  Python-3.6.8.tgz

  这样就是执行编号为325的命令

[root@iZj6c1fa4tkhgpvnd9f12rZ ~]# ls
demo_test  docker_demo  gpu_env  nvidia  Python-3.6.8.tgz
[root@iZj6c1fa4tkhgpvnd9f12rZ ~]# !!
ls
demo_test  docker_demo  gpu_env  nvidia  Python-3.6.8.tgz

  执行刚刚执行过的命令

!num -----执行第几条历史命令
!!     ------执行上一条命令

  

原文地址:https://www.cnblogs.com/Stay-J/p/10911757.html