60 History

發(fā)現(xiàn)我們敲linux命令,很多時候都在不停的切換到這個目錄,又切回這個目錄,都是一些Linux常用命令,這邊我們講的是Linux不常用的命令的linux命令技巧,我們需要在 Bash 中重復(fù)執(zhí)行先前的命令。你當(dāng)然可以使用上方向鍵來查看之前曾經(jīng)運行過的命令。但這里有一些更好的方式:

Linux命令技巧如下;

  1. !!:重復(fù)執(zhí)行上一條指令
[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:重復(fù)執(zhí)行上一條以a為首的指令
[root@li229-122 ~]# touch a
[root@li229-122 ~]# touch b
[root@li229-122 ~]# touch c
[root@li229-122 ~]# !t
touch c
  1. !number:重復(fù)執(zhí)行上一條在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:重復(fù)執(zhí)行前第number條指令
[root@li229-122 ~]# history ^C
[root@li229-122 ~]# !-5
touch d
[root@li229-122 ~]#
  1. !$:表示獲得上一條命令中的參數(shù)
[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表中查詢某條過往指令,找到需要重復(fù)執(zhí)行的命令后,按回車鍵即可重復(fù)命令參數(shù)(即上一點中的第5條)
[root@li229-122 ~]# ^C
(reverse-i-search)`':

然后輸入touch

[root@li229-122 ~]# ^C
(reverse-i-search)`touch': touch c
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容