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

來源:互聯網
上載者:User

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

時常,某個程式或軟體並沒有語法錯誤,並且你檢查它的相關內容也確實沒有發現問題。這是因為你用普通文字編輯器軟體來查看的時候,有許多字元沒有顯示出來,但在終端使用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命令

cat 不能輸出的中文的原因主要在於終端本身設定,你看亂碼,說明終端使用了錯誤的字元集解釋字元,所以才會出現亂碼。比如你使用了windows提供那個telnet登入到Linux中,那麼肯定顯示就是亂碼,因為Linux使用字元集是UTF-8。
解決方案:windows登入Linux,包含開發板、還有PC之類的,推薦使用Putty。如果是Linux是自己,那麼在終端菜單裡面設定一下字元。
 
怎查看linux檔案中是否含有不可見字元

檔案,如果是文字格式設定的,不可見字元始終是不可見的。。。不可見字元有\n, \t, 等,可以參考zhidao.baidu.com/question/21146309.html

如果是想查看目前的目錄下的所有檔案(包括隱藏檔案),可以用 ls -a
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.