[[email protected] ~]$ cat lgrw.txt
cat: lgrw.txt: No such file or directory
[[email protected] ~]$ ^rw^wr
cat lgwr.txt
18:03:19.703928 times({tms_utime=27, tms_stime=18, tms_cutime=0, tms_cstime=0}) = 433678186
18:03:19.704111 semtimedop(1900546, {{15, -1, 0}}, 1, {1, 660000000}) = -1 EAGAIN (Resource temporarily unavailable)
18:03:21.364682 getrusage(RUSAGE_SELF, {ru_utime={0, 278957}, ru_stime={0, 184971}, ...}) = 0
18:03:21.364760 getrusage(RUSAGE_SELF, {ru_utime={0, 278957}, ru_stime={0, 184971}, ...}) = 0
[[email protected] ~]$ history --10
-bash: history: --: invalid option
history: usage: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
[[email protected] ~]$ ^--
history 10
1002 ls -lte
[[email protected] ~]$ echo mount /dev/mapper/vg0-lv1 /data1
mount /dev/mapper/vg0-lv1 /data1
[[email protected] ~]$ !:gs/1/2
echo mount /dev/mapper/vg0-lv2 /data2
mount /dev/mapper/vg0-lv2 /data2
[[email protected] ~]$
引用命令行
![!|[?]string|[-]number]
:[n|x-y|^|$|*|n*|%]:[h|t|r|e|p|s|g]
-------选择word---- ----修饰符-----
!! ---上一条命令
!cat 以cat开头的命令
[[email protected] ~]$ !cat
cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
!?cat 含cat的命令
[[email protected] ~]$ !?cat
cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nolog
!n 第 n 个命令
!-n 倒数第 n 个命令
!$ 上条命令最后一位
!^ 上条命令第一位
!:n 上条命令第 n 位
!:x-y 上条命令 x - y
!:n* 上条 n 到最后
!* 上条所有参数
:h 选取路径开头
:t 选取路径结尾
:r 选取文件名
[[email protected] ~]$ echo a.txt
a.txt
[[email protected] ~]$ !$:t
a.txt
-bash: a.txt: command not found
[[email protected] ~]$ echo !$:r
echo a
a
:e 选取扩展名
[[email protected] ~]$ echo abc.jpg
abc.jpg
[[email protected] ~]$ echo !$:e
echo .jpg
.jpg
:p 打印命令行
[[email protected] ~]$ !e:p
echo .jpg
[[email protected] ~]
:s 做替换
% echo this that
% !:s/is/e
echo the that
惯用法: ^is^e
[[email protected] ~]$ echo this that
this that
[[email protected] ~]$ !:s/is/e
echo the that
the that
[[email protected] ~]$ ^is^e
-bash: :s^is^e: substitution failed
[[email protected] ~]$ echo this that
this that
[[email protected] ~]$ ^is^e
echo the that
the that
[[email protected] ~]$
:g 做全局替换
[[email protected] ~]$ echo abcd abef
abcd abef
[[email protected] ~]$ !:gs/ab/cd
echo cdcd cdef
cdcd cdef
[[email protected] ~]$
深入阅读
- bash: man history
- Bash Reference Manual:
https://www.gnu.org/software/bash/manual/html_node/index.html
- Book: Unix Power Tools
版权声明:本文为博主原创文章,未经博主允许不得转载。