美文网首页
60 History

60 History

作者: StarShift | 来源:发表于2016-12-02 21:31 被阅读26次

    发现我们敲linux命令,很多时候都在不停的切换到这个目录,又切回这个目录,都是一些Linux常用命令,这边我们讲的是Linux不常用的命令的linux命令技巧,我们需要在 Bash 中重复执行先前的命令。你当然可以使用上方向键来查看之前曾经运行过的命令。但这里有一些更好的方式:

    Linux命令技巧如下;

    1. !!:重复执行上一条指令
    [root@li229-122 tmp]# cd /data/site/test.ttlsa.com/
    [root@li229-122 test.ttlsa.com]# ls
    info.php
    [root@li229-122 test.ttlsa.com]# !!
    ls
    info.php
    
    1. !a:重复执行上一条以a为首的指令
    [root@li229-122 ~]# touch a
    [root@li229-122 ~]# touch b
    [root@li229-122 ~]# touch c
    [root@li229-122 ~]# !t
    touch c
    
    1. !number:重复执行上一条在history表中记录号码为number的指令
    [root@li229-122 ~]# history
      41  history
      42  touch a
      43  touch b
      44  touch c
      45  history
    [root@li229-122 ~]# !43
    touch b
    [root@li229-122 ~]#
    
    1. !-number:重复执行前第number条指令
    [root@li229-122 ~]# history ^C
    [root@li229-122 ~]# !-5
    touch d
    [root@li229-122 ~]#
    
    1. !$:表示获得上一条命令中的参数
    [root@li229-122 ~]# a b c e eeeee
    -bash: a: command not found
    [root@li229-122 ~]# !$
    eeeee
    -bash: eeeee: command not found
    
    1. 用Ctrl + r 组合键来进入历史搜索模式在history表中查询某条过往指令,找到需要重复执行的命令后,按回车键即可重复命令参数(即上一点中的第5条)
    [root@li229-122 ~]# ^C
    (reverse-i-search)`':
    

    然后输入touch

    [root@li229-122 ~]# ^C
    (reverse-i-search)`touch': touch c
    

    相关文章

      网友评论

          本文标题:60 History

          本文链接:https://www.haomeiwen.com/subject/awwypttx.html