感叹号在Linux bash中使用技巧
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条)
感叹号在Linux bash中使用技巧的更多相关文章
- Linux bash 中,如何将正常信息和错误信息输出到文件
问题描述: $ command 2>> error $ command 1>> output 是否有方法,在bash同一行,实现输出stderr到error文件,输出stdou ...
- linux bash中too many arguments问题的解决方法
今天在编写shell脚本时,在if条件后跟的是[ $pid ],执行脚本的时候报 然后我输入改为[[$pid]]后,再执行脚本,就成功了,代码如下: #!/bin/bash pid=`ps -ef|g ...
- 在Linux系详解Linux bash中的变量
(大讲台:国内首个it在线教育混合式自适应学习) 统中进行日常运维或者是编写脚本时,变量是再熟悉不过的了,但这些变量都有哪些类型,具体的用法又有哪些差异呢?本文整理分享给大家: 一.bash变量类型: ...
- Linux bash中的变量分类
1.本地变量 VAR=XYZ 2.局部变量 local VAR=XYZ 3.环境变量 在子shell中可以起作用 export VAR=XYZ 4.位置变量 $0 脚本名本身 $1 第一个参数 $2 ...
- Linux Bash脚本编程语言中的美学与哲学
我承认,我再一次地当了标题党.但是不可否认,这一定是一篇精华随笔.在这一篇中,我将探讨Bash脚本语言中的美学与哲学. 这不是一篇Bash脚本编程的教程,但是却能让人更加深入地了解Bash脚本编程,更 ...
- Linux小知识(1): bash中执行数据库的相关操作
工作中经常会遇到命令行操作数据库或登陆至其他服务器等情况,往往需要通过命令行进入相关的数据库或登陆至相关的服务器,再执行指令操作,因此有没有方法,在命令行或bash脚本中模拟进入数据库或登陆服务器操作 ...
- Linux系统中命令提示符解释-Linux中命令格式、分类-bash中的快捷键
1.命令提示符 [root@mysqlserver01 opt]# [root@mysqlserver01 ~]# root 当前用户名 @ 固定的(格式) mysqlserver01 主机名 opt ...
- 在Windows中运行Linux bash命令的几种方法
如果你正在课程中正在学习 shell 脚本,那么需要使用 Linux 命令来练习命令和脚本. 你的学校实验室可能安装了 Linux,但是你自己没有安装了 Linux 的笔记本电脑,而是像其他人一样的 ...
- find查找文件命令 - Linux系统中的常用技巧整理
“find”在Linux系统中是比较常用的文件查找命令,使用方法有很多,可以拥有查找文件.文件目录.文件更新时间.文件大小.文件权限及对比文件时间.下面是整理的“find”常用方法,方便以后需要的时候 ...
随机推荐
- css 字符过长...
text-overflow: ellipsis; white-space: nowrap; overflow: hidden; overflow: hidden; white-space: nowra ...
- 使用mysql的注意事项
1,文件导入:LOAD DATA INFILE '/tmp/pet.txt' INTO TABLE pet FIELDS TERMINATED BY ',' LINES TERMINATED BY ' ...
- nginx如何一个域名多个端口?
方法一 写三个 listen server { listen 80; listen 81; listen 82; server_name www.sifou.com; ... 方法二 写三个serve ...
- 小程序调用wx.chooseLocation接口的时候无法获取权限(ios)
ios手机小程序调用wx.chooseLocation接口的时候,获取权限的时候报authorize:fail:require permission desc这样子的错误,这是由于苹果的安全机制导致需 ...
- 干货 | 京东技术中台的Flutter实践之路
在 2019 年,Flutter 推出了多个正式版本,支持的终端越来越多,使用的项目也越来越多.Flutter 正在经历从小范围尝鲜到大面积应用的过程,越来越多的研发团队加入到 Flutter 的学习 ...
- 吴裕雄--天生自然 JAVASCRIPT开发学习: 表单验证
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 双向链表的双向冒泡排序 c++
#include<iostream> using namespace std; #define swap(a,b) {int t;t = a;a = b;b = t;} //节点类型的定义 ...
- android stutio 添加依赖
添加依赖有 3种方法: 1 :copy jar 包到libs目录 ,add to library 2: copy aar 文件到libs ,gradle 文件 android 节点添加 repo ...
- Eclipse打开,出现Initializing Java Tooling “has encountered a problem错误,而且鼠标悬停在没有导包的类上面不会出现import信息。
问题1:打开eclipse,出现了Initializing Java Tooling “has encountered a problem,点开详细信息,报的是空指针异常. 问题2:鼠标悬停在没有导包 ...
- PHP静态方法和普通方法的区别
<?php header('content-type:text/html;charset=utf-8'); /* 普通方法,存放类内,只有一份 静态方法,也是存放于类内,只有一份 区别在于:普通 ...