Linux常用基本命令wc-統計文件的字節,字符,行數


wc命令

作用:統計文件的字節,單詞,行數

用法:wc [option] [file]

 

-c:統計字節

ghostwu@dev:~/linux/uniq$ cat ghostwu.txt 
192.168.1.2
192.168.1.8
192.168.1.3
192.168.1.3
192.168.1.9
192.168.1.8
192.168.1.8
192.168.1.0
192.168.1.3
ghostwu@dev:~/linux/uniq$ wc -c ghostwu.txt 
108 ghostwu.txt
ghostwu@dev:~/linux/uniq$ ls -lh
total 4.0K
-rw-rw-r-- 1 ghostwu ghostwu 108 5月  20 19:45 ghostwu.txt

-l : 統計行數:

ghostwu@dev:~/linux/uniq$ cat -n ghostwu.txt 
     1    192.168.1.2
     2    192.168.1.8
     3    192.168.1.3
     4    192.168.1.3
     5    
     6    
     7    192.168.1.9
     8    192.168.1.8
     9    192.168.1.8
    10    192.168.1.0
    11    192.168.1.3
ghostwu@dev:~/linux/uniq$ wc -l ghostwu.txt 
11 ghostwu.txt

-m: 統計字符

ghostwu@dev:~/linux/uniq$ cat char.txt 
hello,my name is ghostwu
ghostwu@dev:~/linux/uniq$ wc -m char.txt 
25 char.txt

-c: 統計字節

ghostwu@dev:~/linux/uniq$ wc -c char.txt 
25 char.txt

-c與-m的區別,"你好啊" 是3個字符,占用9個字節。一般情況下,一個中文在utf8編碼下,占用3個字節

ghostwu@dev:~/linux/uniq$ wc -m char.txt 
29 char.txt
ghostwu@dev:~/linux/uniq$ wc -c char.txt 
35 char.txt
ghostwu@dev:~/linux/uniq$ cat char.txt 
hello,my name is ghostwu
你好啊

-w: 統計單詞,空格隔開才算一個單詞

ghostwu@dev:~/linux/uniq$ cat char.txt 
hello,my name is ghostwu
你好啊
ghostwu@dev:~/linux/uniq$ vim char.txt 
ghostwu@dev:~/linux/uniq$ wc -w char.txt 
7 char.txt
ghostwu@dev:~/linux/uniq$ vim char.txt 
ghostwu@dev:~/linux/uniq$ cat char.txt 
hello my name is ghostwu
你 好 啊
ghostwu@dev:~/linux/uniq$ wc -w char.txt 
8 char.txt

-L:打印最長行的長度

ghostwu@dev:~/linux/uniq$ wc -L char.txt 
24 char.txt

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM