Linux終端:用cat命令查看不可見字元

來源:互聯網
上載者:User

標籤:cat   linux指令碼   shell   

時常,某個程式或軟體並沒有語法錯誤,並且你檢查它的相關內容也確實沒有發現問題。這是因為你用普通文字編輯器軟體來查看的時候,有許多字元沒有顯示出來,但在終端使用cat命令可以很容易地檢測出是否存在這些字元。

~首先,我們建立一個簡單的文字檔,寫入一些特殊字元。開啟終端,運行命令:

printf ‘testing\012\011\011testing\014\010\012more testing\012\011\000\013\000even more testing\012\011\011\011\012‘ > /tmp/testing.txt 


現在用不同的編輯器軟體開啟,顯示的結果會不同。用簡單的cat開啟將顯示:

$ cat /tmp/testing.txt  

testing 

testing

more testing

even more testing 


如果用nano或者vim開啟,將會看到:

testing 

testing^L^H

more testing 

^@^K^@even more testing 


現在我們給cat加上一些選項參數,以便能顯示出特殊字元來。

用cat -T命令來顯示TAB鍵的字元^I

cat -T /tmp/testing.txt 

testing 

^I^Itesting

more testing 

^I 

even more testing 

^I^I^I 


用cat -E命令來顯示行尾的結束字元$

$ cat -E /tmp/testing.txt 

testing$ 

testing 

$ 

more testing$

even more testing$ 

$ 


用簡單的cat -A命令就可以顯示所有不可見的字元:

$ cat -A /tmp/testing.txt 

testing$ 

^I^Itesting^L^H$ 

more testing$ 

^I^@^K^@even more testing$ 

^I^I^I$


Linux終端:用cat命令查看不可見字元

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.