歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> linux基礎之bash特性

linux基礎之bash特性

日期:2017/3/3 13:49:05   编辑:Linux技術

光標跳轉:

[code]Ctrl+a:跳到命令行首
Ctrl+e:跳到命令行尾
Ctrl+u: 刪除光標至命令行首的內容
Ctrl+k: 刪除光標至命令行尾的內容
Ctrl+l: 清屏

命令歷史的使用技巧:

[code]!n:執行命令歷史中的第n條命令;
!-n:執行命令歷史中的倒數第n條命令; 
!!: 執行上一條命令;
!string:執行命令歷史中最近一個以指定字符串開頭的命令
!$:引用前一個命令的最後一個參數; 
按下Esc鍵松開再按 “.” 也可以實現!$的功能
Alt + .也可以實現!$的功能

命令替換

把命令中某個子命令替換為其結果的過程 例:

[code][root@iZ28g26851kZ ~]# echo The current directory is $(pwd)
The current directory is /root
[root@iZ28g26851kZ ~]# cd /opt/
[root@iZ28g26851kZ opt]# echo The current directory is $(pwd)
The current directory is /opt
[root@iZ28g26851kZ opt]#
一般格式為

$(command)

例2:創建一個文件,文件名為當前日期時間

[code][root@iZ28g26851kZ opt]# touch $(date +%F-%H:%M:%S)_log.txt
[root@iZ28g26851kZ opt]# ls
2016-05-05-10:20:24_log.txt  rh  test  x
[root@iZ28g26851kZ opt]# touch $(date +%F-%H:%M:%S)_log.txt
[root@iZ28g26851kZ opt]# ls
2016-05-05-10:20:24_log.txt  2016-05-05-10:20:37_log.txt  rh  test  x
[root@iZ28g26851kZ opt]#

bash支持的引號

[code]``:命令替換
"":弱引用,可以實現變量替換
'':強引用,不完成變量替換

文件通配符

[code]*:匹配任意長度的任意字符
?:匹配任意單個字符
[]:匹配指定范圍內的任意單個字符
    [:space:]:空白字符
    [:punct:]:標點符號
    [:lower:]:小寫字母
    [:upper:]:大寫字母
    [:alpha:]:大小寫字母
    [:digit:]:數字
    [:alnum:]:數字和大小寫字母
    當然這些都可以用命令 man 7 glob 查看

[^]:匹配指定范圍之外的任意單個字符
例如:我們要查找一個文件名中間有是空格字符的文件

[code][root@iZ28g26851kZ opt]# ll
total 4
-rw-r--r--  1 root root    0 May  5 10:48 a b
-rw-r--r--  1 root root    0 May  5 10:48 asd
-rw-r--r--  1 root root    0 May  5 10:48 gfsd
drwxr-xr-x. 2 root root 4096 Nov 22  2013 rh
[root@iZ28g26851kZ opt]# ll *[[:space:]]*
-rw-r--r-- 1 root root 0 May  5 10:48 a b
[root@iZ28g26851kZ opt]#

Copyright © Linux教程網 All Rights Reserved