發現我們敲linux命令,很多時候都在不停的切換到這個目錄,又切回這個目錄,都是一些Linux常用命令,這邊我們講的是Linux不常用的命令的linux命令技巧,我們需要在 Bash 中重復執行先前的命令。你當然可以使用上方向鍵來查看之前曾經運行過的命令。但這里有一些更好的方式:
Linux命令技巧如下;
- !!:重復執行上一條指令
[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
- !a:重復執行上一條以a為首的指令
[root@li229-122 ~]# touch a
[root@li229-122 ~]# touch b
[root@li229-122 ~]# touch c
[root@li229-122 ~]# !t
touch c
- !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 ~]#
- !-number:重復執行前第number條指令
[root@li229-122 ~]# history ^C
[root@li229-122 ~]# !-5
touch d
[root@li229-122 ~]#
- !$:表示獲得上一條命令中的參數
[root@li229-122 ~]# a b c e eeeee
-bash: a: command not found
[root@li229-122 ~]# !$
eeeee
-bash: eeeee: command not found
- 用Ctrl + r 組合鍵來進入歷史搜索模式在history表中查詢某條過往指令,找到需要重復執行的命令后,按回車鍵即可重復命令參數(即上一點中的第5條)
[root@li229-122 ~]# ^C
(reverse-i-search)`':
然后輸入touch
[root@li229-122 ~]# ^C
(reverse-i-search)`touch': touch c