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