歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> linux命令技巧

linux命令技巧

日期:2017/3/1 12:26:34   编辑:關於Linux
[oracle@rh64 ~]$ cat lgrw.txt cat: lgrw.txt: No such file or directory [oracle@rh64 ~]$ ^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
[oracle@rh64 ~]$ history --10 -bash: history: --: invalid option history: usage: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...] [oracle@rh64 ~]$ ^-- history 10 1002 ls -lte [oracle@rh64 ~]$ echo mount /dev/mapper/vg0-lv1 /data1 mount /dev/mapper/vg0-lv1 /data1 [oracle@rh64 ~]$ !:gs/1/2 echo mount /dev/mapper/vg0-lv2 /data2 mount /dev/mapper/vg0-lv2 /data2 [oracle@rh64 ~]$

引用命令行 ![!|[?]string|[-]number]
:[n|x-y|^|$|*|n*|%]:[h|t|r|e|p|s|g] -------選擇word---- ----修飾符-----
!! ---上一條命令 !cat 以cat開頭的命令 [oracle@rh64 ~]$ !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的命令 [oracle@rh64 ~]$ !?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 選取文件名 [oracle@rh64 ~]$ echo a.txt a.txt [oracle@rh64 ~]$ !$:t a.txt -bash: a.txt: command not found [oracle@rh64 ~]$ echo !$:r echo a a :e 選取擴展名 [oracle@rh64 ~]$ echo abc.jpg abc.jpg [oracle@rh64 ~]$ echo !$:e echo .jpg .jpg
:p 打印命令行 [oracle@rh64 ~]$ !e:p echo .jpg [oracle@rh64 ~]
:s 做替換 % echo this that % !:s/is/e echo the that 慣用法: ^is^e [oracle@rh64 ~]$ echo this that this that [oracle@rh64 ~]$ !:s/is/e echo the that the that [oracle@rh64 ~]$ ^is^e -bash: :s^is^e: substitution failed [oracle@rh64 ~]$ echo this that this that [oracle@rh64 ~]$ ^is^e echo the that the that [oracle@rh64 ~]$
:g 做全局替換 [oracle@rh64 ~]$ echo abcd abef abcd abef [oracle@rh64 ~]$ !:gs/ab/cd echo cdcd cdef cdcd cdef [oracle@rh64 ~]$
Copyright © Linux教程網 All Rights Reserved