感叹号在Linux bash中使用技巧
2024-09-28 21:37:13
1. 重复执行上一条指令 !!
[root@iZ23t6nzr7dZ python]# ls /usr/local/
aegis bin etc games include lib lib64 libexec python3 sbin share src
[root@iZ23t6nzr7dZ python]# !!
ls /usr/local/
aegis bin etc games include lib lib64 libexec python3 sbin share src
[root@iZ23t6nzr7dZ python]#
2. 重复执行上一条以a为首的指令 !a
[root@iZ23t6nzr7dZ python]# history
rpm -qf /usr/bin/pwd
rpm -ql coreutils
clear
/usr/local/
ls /usr/local/
ls ls /usr/local/
ls /usr/local/
ls -al /usr/local/
vim /etc/shadow
ls
vim /etc/passwd
clear
ls
cp -rf ./* /tmp/
262 ls -l /tmp/
263 ls -l
264 clear
265 ls /usr/local/
266 history
[root@iZ23t6nzr7dZ python]# !rpm
rpm -ql coreutils
/etc/DIR_COLORS
/etc/DIR_COLORS.256color
/etc/DIR_COLORS.lightbgcolor
/etc/profile.d/colorls.csh
/etc/profile.d/colorls.sh
/usr/bin/[
/usr/bin/arch
/usr/bin/base64
3. 重复执行上一条在history表中记录号码为number的指令 !number
[root@iZ23t6nzr7dZ python]#history
clear
ls
cp -rf ./* /tmp/
262 ls -l /tmp/
263 ls -l
264 clear
265 ls /usr/local/
266 history
267 rpm -ql coreutils
268 clear
269 history
[root@iZ23t6nzr7dZ python]# !267
rpm -ql coreutils
/etc/DIR_COLORS
/etc/DIR_COLORS.256color
/etc/DIR_COLORS.lightbgcolor
/etc/profile.d/colorls.csh
/etc/profile.d/colorls.sh
/usr/bin/[
/usr/bin/arch
4.重复执行前第number条指令 !-number
5. 表示获得上一条命令中的最后一项内容 !$
[root@iZ23t6nzr7dZ python]# ls -l /usr/local/python3/bin/ /etc/passwd
-rw-r--r-- root root Jan : /etc/passwd /usr/local/python3/bin/:
total
lrwxrwxrwx root root Jan : 2to3 -> 2to3-3.7
-rwxr-xr-x root root Jan : 2to3-3.7
-rwxr-xr-x root root Jan : chardetect
-rwxr-xr-x root root Jan : easy_install-3.7
lrwxrwxrwx root root Jan : idle3 -> idle3.
-rwxr-xr-x root root Jan : idle3.
-rwxr-xr-x root root Jan : pip3
-rwxr-xr-x root root Jan : pip3.
lrwxrwxrwx root root Jan : pydoc3 -> pydoc3.
-rwxr-xr-x root root Jan : pydoc3.
lrwxrwxrwx root root Jan : python3 -> python3.
-rwxr-xr-x root root Jan : python3.
lrwxrwxrwx root root Jan : python3.-config -> python3.7m-config
-rwxr-xr-x root root Jan : python3.7m
-rwxr-xr-x root root Jan : python3.7m-config
lrwxrwxrwx root root Jan : python3-config -> python3.-config
lrwxrwxrwx root root Jan : pyvenv -> pyvenv-3.7
-rwxr-xr-x root root Jan : pyvenv-3.7
[root@iZ23t6nzr7dZ python]# cat !$
cat /etc/passwd
root:x:::root:/root:/bin/bash
bin:x:::bin:/bin:/sbin/nologin
daemon:x:::daemon:/sbin:/sbin/nologin
6. 表示获得上一条命令中的第一个参数 !^
[root@iZ23t6nzr7dZ python]#
[root@iZ23t6nzr7dZ python]# ls -l /usr/local/python3/bin/ /etc/passwd
-rw-r--r-- root root Jan : /etc/passwd /usr/local/python3/bin/:
total
lrwxrwxrwx root root Jan : 2to3 -> 2to3-3.7
-rwxr-xr-x root root Jan : 2to3-3.7
-rwxr-xr-x root root Jan : chardetect
-rwxr-xr-x root root Jan : easy_install-3.7
lrwxrwxrwx root root Jan : idle3 -> idle3.
-rwxr-xr-x root root Jan : idle3.
-rwxr-xr-x root root Jan : pip3
-rwxr-xr-x root root Jan : pip3.
lrwxrwxrwx root root Jan : pydoc3 -> pydoc3.
-rwxr-xr-x root root Jan : pydoc3.
lrwxrwxrwx root root Jan : python3 -> python3.
-rwxr-xr-x root root Jan : python3.
lrwxrwxrwx root root Jan : python3.-config -> python3.7m-config
-rwxr-xr-x root root Jan : python3.7m
-rwxr-xr-x root root Jan : python3.7m-config
lrwxrwxrwx root root Jan : python3-config -> python3.-config
lrwxrwxrwx root root Jan : pyvenv -> pyvenv-3.7
-rwxr-xr-x root root Jan : pyvenv-3.7
[root@iZ23t6nzr7dZ python]# ls !^
ls -l
total
-rw-r--r-- root root Jan : .py
-rw-r--r-- root root Jan : .py
-rw-r--r-- root root Jan : .py
-rw-r--r-- root root Jan : links.txt
-rw-r--r-- root root Jan : wangping_links_2.txt
-rw-r--r-- root root Jan : wp_links_2.txt
7.上一命令除了最后一个参数 !:-
[root@iZ23t6nzr7dZ python]# ls -l /etc/passwd /home/python/
-rw-r--r-- root root Jan : /etc/passwd /home/python/:
total
-rw-r--r-- root root Jan : .py
-rw-r--r-- root root Jan : .py
-rw-r--r-- root root Jan : .py
-rw-r--r-- root root Jan : links.txt
-rw-r--r-- root root Jan : wangping_links_2.txt
-rw-r--r-- root root Jan : wp_links_2.txt
[root@iZ23t6nzr7dZ python]# !:-
ls -l /etc/passwd
-rw-r--r-- root root Jan : /etc/passwd
[root@iZ23t6nzr7dZ python]#
8.上一条命令中的所有参数 !*
[root@iZ23t6nzr7dZ python]#
[root@iZ23t6nzr7dZ python]# ls /etc/passwd /home/python/.py
/etc/passwd /home/python/.py
[root@iZ23t6nzr7dZ python]# ls -l !*
ls -l /etc/passwd /home/python/.py
-rw-r--r-- root root Jan : /etc/passwd
-rw-r--r-- root root Jan : /home/python/.py
[root@iZ23t6nzr7dZ python]#
9.使用上条命令指定的参数 ![命令名]:[参数号]
$ cp -rf dira dirb/ #将dira拷贝到dirb $ ls -l !cp: #查看dira的内容 ls -l dira total -rw-rw-r-- hyb hyb Jan : barfile
10. 用Ctrl + r 组合键来进入历史搜索模式在history表中查询某条过往指令,找到需要重复执行的命令后,按回车键即可重复命令参数(即上一点中的第5条)
最新文章
- Hibernate内测总结
- 9个让人印象深刻的网站 JS 视觉效果
- JavaScript高级程序设计 读书笔记 第二章
- js中arguments的用法
- linux service
- 刷新拜拜~gulp-livereload
- 【BZOJ 1503】【NOI 2004】郁闷的出纳员
- codeforces A. IQ Test 解题报告
- HDU3037 Saving Beans(Lucas定理+乘法逆元)
- hiho 毁灭者问题
- makefile missing separator. Stop
- Linux数据管理——文件锁定
- phpmyadmin安装出错,缺少 mysqli 扩展。请检查 PHP 配置
- cocos2d 高仿doodle jump 无源代码
- 算法学习 - 图的广度优先遍历(BFS) (C++)
- 自制 Word、Excel 批转 PDF 工具
- SQLServer修改登陆账户信息
- selenium-弹窗操作(八)
- ShoppingCart类图
- PHP-1安装配置
热门文章
- freeswitch初识
- nodejs(16)使用express.static快速托管静态资源
- selenium破解人人登陆验证码
- UML-对象设计要迭代和进化式
- Go-并发和并行-协程-信道-缓冲信道-select-mutex-读写文件-beego框架
- ZJNU 2340/2341/2343 - 罗小黑的“礼物”Ⅰ/Ⅱ/Ⅲ
- 洛谷 P2320 [HNOI2006]鬼谷子的钱袋
- bfs--P1443 马的遍历
- 【MySQL参数】-innodb_additional_mem_pool_size
- Akka Typed系列:协议&;行为