摘要
发现我们敲linux命令,很多时候都在不停的切换到这个目录,又切回这个目录,都是一些Linux常用命令,这边我们讲的是Linux不常用的命令的linux命令技巧,我们需要在 Bash 中重复执行先前的命令。你当然可以使用上方向键来查看之前曾经运行过的命令。但这里有一些更好的方式:
Linux命令技巧如下;
1. !!:重复执行上一条指令
2. !a:重复执行上一条以a为首的指令
3. !number:重复执行上一条在history表中记录号码为number的指令
4. !-number:重复执行前第number条指令
5. !$:表示获得上一条命令中的最后一项内容
6. 用Ctrl + r 组合键来进入历史搜索模式在history表中查询某条过往指令,找到需要重复执行的命令后,按回车键即可重复命令参数(即上一点中的第5条)
Linux命名技巧1
以下是Linux命令技巧的实例:
发现我们敲linux命令,很多时候都在不停的切换到这个目录,又切回这个目录,都是一些Linux常用命令,这边我们讲的是Linux不常用的命令的linux命令技巧,我们需要在 Bash 中重复执行先前的命令。你当然可以使用上方向键来查看之前曾经运行过的命令。但这里有一些更好的方式:
Linux命令技巧如下;
1. !!:重复执行上一条指令
2. !a:重复执行上一条以a为首的指令
3. !number:重复执行上一条在history表中记录号码为number的指令
4. !-number:重复执行前第number条指令
5. !$:表示获得上一条命令中的最后一项内容
6. 用Ctrl + r 组合键来进入历史搜索模式在history表中查询某条过往指令,找到需要重复执行的命令后,按回车键即可重复命令参数(即上一点中的第5条)
Linux命名技巧1
以下是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
1
2
3
4
5
6
[root@li229-122tmp]# cd /data/site/test.ttlsa.com/
[root@li229-122test.ttlsa.com]# ls
info.php
[root@li229-122test.ttlsa.com]# !!
ls
info.php
如上命令,大家可以看到我输入!!,实际上是重复了上一条命令ls
Linux命名技巧2
[root@li229-122 ~]# touch a
[root@li229-122 ~]# touch b
[root@li229-122 ~]# touch c
[root@li229-122 ~]# !t
touch c
1
2
3
4
5
[root@li229-122~]# touch a
[root@li229-122~]# touch b
[root@li229-122~]# touch c
[root@li229-122~]# !t
touchc
如果上命令,可以看到敲了三个touch命令,输入!t,他匹配了我最后一条的touch c命令
Linux命令技巧3
[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
2
3
4
5
6
7
8
9
[root@li229-122~]# history
41history
42toucha
43touchb
44touchc
45history
[root@li229-122~]# !43
touchb
[root@li229-122~]#
如上命令,history看到了history的编号。接着!43执行的是编号为43的touch b
Linux命令技巧4
[root@li229-122 ~]# history
41 touch a
42 history
43 touch a
44 touch c
45 touch d
46 history
47 touch c
48 touch 2
49 history
[root@li229-122 ~]# history ^C
[root@li229-122 ~]# !-5
touch d
[root@li229-122 ~]#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@li229-122~]# history
41toucha
42history
43toucha
44touchc
45touchd
46history
47touchc
48touch2
49history
[root@li229-122~]# history ^C
[root@li229-122~]# !-5
touchd
[root@li229-122~]#
如上命令,可以看到我们执行了linux历史记录命令中倒数第五条
Linux命令技巧5
[root@li229-122 ~]# a b c e eeeee
-bash: a: command not found
[root@li229-122 ~]# !$
eeeee
-bash: eeeee: command not found
1
2
3
4
5
[root@li229-122~]# a b c e eeeee
-bash:a:commandnotfound
[root@li229-122~]# !$
eeeee
-bash:eeeee:commandnotfound
如上命令,当然这些命令是我乱输的,可以发现获取到的是命令最后一个参数
Linux命令技巧6
安装ctrl + r,出现如下内容:
[root@li229-122 ~]# ^C
(reverse-i-search)`':
1
2
[root@li229-122~]# ^C
(reverse-i-search)`':
接着输入touch
[root@li229-122 ~]# ^C
(reverse-i-search)`touch': touch c
1
2
[root@li229-122~]# ^C
(reverse-i-search)`touch':touchc
便出现了相关命令touch c.找临时命令会比较方便
转载请注明出处:6个实用的linux命令 - http://www.ttlsa.com/html/1687.html