日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Bash基础(2) 通配符 组合键 数据重定向 管道 tee

發布時間:2025/3/21 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Bash基础(2) 通配符 组合键 数据重定向 管道 tee 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Bash基礎(2)

????通配符? 組合鍵? 數據重定向? 管道? tee命令

?

1?文本名“通配符”

*:匹配任意長度的任意字符;

?:匹配任意單個字符;

????[]:?匹配指定范圍內的任意單個字符;

[0-9]

[^]:匹配范圍外的任意單個字符;

[^a-b]

?

字符集合:

?[:lower:]?匹配任何小寫字母

?[:upper:]?匹配任何大寫字母

?[:alnum:]?匹配任何字母

?[:digit:]??匹配任何數字

?[:space:]?匹配空格符

?[:punct:]?匹配任何標點符號

?[:alnum:]?匹配任何字母

?示例

#顯示/etc/下文件名剛好是3個的文件名[roger@oc3137372501?~]$?ll?-d?/etc/??? drwxr-xr-x.??7?root?root?4096?Jul?24?09:59?/etc/gdm drwxr-xr-x.??3?root?root?4096?Jun?19??2014?/etc/hal drwxr-xr-x.??4?root?root?4096?Feb?25??2014?/etc/ibm drwxr-xr-x.??2?root?root?4096?May?27??2010?/etc/jvm drwxr-xr-x.??5?root?root?4096?May?25?09:13?/etc/kde drwxr-xr-x.??6?root?root?4096?Jul?24?10:00?/etc/lvm drwxr-xr-x.??3?root?root?4096?Jul?24?10:03?/etc/ntp drwxr-xr-x.??4?root?root?4096?Feb?25??2014?/etc/opt drwxr-xr-x.?10?root?root?4096?Feb?25??2014?/etc/pki#顯示/etc/下以ss開頭的文件名 [roger@oc3137372501?~]$?ll?-d?/etc/ss* drwxr-xr-x.?2?root?root?4096?Jul?24?09:57?/etc/ssh drwxr-xr-x.?2?root?root?4096?Jul?24?09:40?/etc/ssl#顯示/etc/下文件名中含有數字0-3的文件名 [roger@oc3137372501?~]$?ll?-d?/etc/*[0-3]* drwxr-xr-x.?4?root?root?4096?Jul?24?09:38?/etc/dbus-1 -rw-r--r--.?1?root?root?5139?Jul?16??2014?/etc/DIR_COLORS.256color drwxr-xr-x.?3?root?root?4096?May?13??2010?/etc/gnome-vfs-2.0 drwxr-xr-x.?2?root?root?4096?May??7?17:24?/etc/gtk-2.0 drwxr-xr-x.?2?root?root?4096?Jul?24?09:56?/etc/iproute2


2?組合鍵

??Ctrl+l:清屏

??Ctrl+a:?切換至命令行首

??Ctrl+e:切換至命令行尾

??Ctrl+c:取消命令執行

??Ctrl+m:就是回車

??Ctrl+s:暫停屏幕輸出

??Ctrl+q:恢復屏幕輸出

??Ctrl+z:?暫停目前命令

??Ctrl+u:刪除光標所在處至行首的內容;

??Ctrl+k:?刪除光標所在處至行尾的內容;

?

3?數據流重定向

??程序:指令+數據

讀入數據:input?

輸出數據:output?

??

??標準輸入(stdin):?keyboard?代碼為0,使用<<<??/dev/stdin

??標準輸出(stdout):?monitor?代碼為1,使用>>>??/dev/stdout

??標準錯誤輸出(stderr):?monitor?代碼為2,使用2>?2>>??/dev/stderr

??

?輸出重定向:

????COMMAND?>?NEW_POS,?COMMAND?>>?NEW_POS

>?覆蓋的方式輸出

>>?追加的方式輸出

?

?set?-C?開啟如果覆蓋重定向目標文件存在,則禁止執行;

?set?+C?關閉如果覆蓋重定向目標文件存在,則禁止執行;

?

?同時重定向標準輸出流和錯誤輸出流:

?

#輸出到不同的文件COMMAND?>?/path/to/file.out?2>?/path/to/file.err[roger@oc3137372501?~]$?rm?/?>test/right_file?2>test/err_file#輸出到同一文件夾COMMAND?>?/path/to/file.out?2>&1[roger@oc3137372501?~]$?rm?/?>test/test_file?2>&1COMMAND?&>?/path/to/file.out[roger@oc3137372501?~]$?rm?/?&>test/out_file


?

輸入重定向:

<

用文件內容來代替鍵盤輸入

[roger@oc3137372501?test]$?cat?>?catfile?<?err_file? [roger@oc3137372501?test]$?cat?catfile? rm:?cannot?remove?`/':?Is?a?directory


<<?代表結束輸入的意思

Here?Document<<

cat?>>?/path/to/somefile?<<?EOF

?

tr?命令:用來從標準輸入中通過替換或刪除操作進行字符轉換

語法:tr?-d?-s?["string1_to_translate_from"]["string2_to_translate_to"]

參數:

-d?刪除信息中string1字符串

-s?替換重復字符串

#替換字符串 [roger@oc3137372501?test]$?cat?catfile? how?are?you?? how?old?are?you? aaa ttt ccc kkk [roger@oc3137372501?test]$?tr?ttt?111?<?catfile? how?are?you?? how?old?are?you? aaa 111 ccc kkk #刪除信息中a字符串 [roger@oc3137372501?test]$?tr?-d?a?<?catfile? how?re?you?? how?old?re?you?ttt ccc Kkk #替換重復字符串?替換連續重復字符 [roger@oc3137372501?test]$?tr?-s?t?t?<?catfile? how?are?you?? how?old?are?you? aaa t ccc kkk


4 管道命令pipe:

?COMMAND1?|?COMMAND2?|?COMMAND3...

示例:

[roger@oc3137372501?test]$?ls?-al?/etc?|?more total?2492 drwxr-xr-x.?136?root?root????12288?Aug?25?17:26?. dr-xr-xr-x.??28?root?root?????4096?Aug?25?09:14?.. drwxr-xr-x.???4?root?root?????4096?Feb?25??2014?acpi -rw-r--r--.???1?root?root???????46?Aug?24?18:56?adjtime.....


管道命令僅會處理standard?output,對于standard?error?output?會忽略

管道命令必須能夠接收來自前一個命令的數據成為standard?input繼續處理才行


5tee命令
讀取標準輸入,把這些內容同時輸出到標準輸出和(多個)文件中。
語法:tee [OPTION]... [FILE]...
參數:
? -a: 追加輸出,不覆蓋
? -i: 忽略中斷
示例:

#?tee?只是標準輸出?后邊沒有參數 [roger@oc3137372501?test]$?tee?<?catfile? how?are?you?? how?old?are?you? aaa ttt ccc Kkk#tee?-?兩次標準輸出 [roger@oc3137372501?test]$?tee?-?<?catfile? how?are?you?? how?old?are?you? aaa ttt ccc kkk how?are?you?? how?old?are?you? aaa ttt ccc Kkk#?tee?file?標準輸出的同時,輸出到file?如果file不存在?則創建文件 [roger@oc3137372501?test]$?cat?catfile?|?tee?test_tree how?are?you?? how?old?are?you? aaa ttt ccc Kkk [roger@oc3137372501?test]$?cat?test_tree? how?are?you?? how?old?are?you? aaa ttt ccc kkk#?tee?-a?file?不覆蓋文件,追加輸出到文件 [roger@oc3137372501?test]$?cat?catfile?|?tee?-a?test_tree how?are?you?? how?old?are?you? aaa ttt ccc kkk [roger@oc3137372501?test]$?cat?test_tree? how?are?you?? how?old?are?you? aaa ttt ccc kkk how?are?you?? how?old?are?you? aaa ttt ccc Kkk#?tee?file1?file2...輸出到多個文件 [roger@oc3137372501?test]$?cat?catfile?|?tee?file1?file2? how?are?you?? how?old?are?you? aaa ttt ccc kkk


如有錯誤,敬請指正!

謝謝!

轉載于:https://blog.51cto.com/rogerwang/1688152

總結

以上是生活随笔為你收集整理的Bash基础(2) 通配符 组合键 数据重定向 管道 tee的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。