Linux历史管理命令

history管理历史命令

【1】、history命令

  • history命令用于显示历史记录和执行过的命令,登录系统时,会读取~./bash_history历史文件中记录的命令,当我们退出shell时,我们新敲的命令会被追加保存到~./bash_history

  • history默认保存1000条,可以通过/etc/profile文件去修改

     45 HOSTNAME=`/usr/bin/hostname 2>/dev/null`
     46 HISTSIZE=1000
    

【2】、option

  • -a:命令 -a ,把命令立刻同步到~./bash_history中,不用等到退出shell后在进行同步
  • -d:删除历史命令中的指定命令,后面加历史命令编号
  • -c:清空历史命令列表

【3】、快捷操作

  • !:调动历史命令中的第N条

      576  ll
      577  ls
      578  ll
      579  sl
      580  ll
      581  history
    [root@xuruizhao ~]# !576
    ll
    total 5732
    -rw-------.  1 root root    1046 Mar 18 13:30 anaconda-ks.cfg
    drwxrwxrwx.  2  500  500    4096 Mar 24 11:51 cmatrix-1.2a
    -rw-r--r--.  1 root root   74376 Mar 31  2002 cmatrix-1.2a.tar.gz
    drwxr-xr-x. 12 1001 1001    4096 Mar 24 10:14 httpd-2.2.32
    -rw-r--r--.  1 root root 5777509 Mar 24 10:10 httpd-2.2.32.tar.bz2
    
    
  • !string:调用历史命令中以string开头的命令

    如果有很多个以string开始的命令,则执行最后一个

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

posted @ 2024-07-01 15:07  Linux小菜鸟  阅读(3)  评论(0编辑  收藏  举报