簡單了解wc命令
2016-11-16 21:15:53
25943
wc命令用來打印文件的文本行數(shù)、單詞數(shù)、字節(jié)數(shù)等(print the number of newlines, words, and bytes in files)。在Windows的Word中有個“字?jǐn)?shù)統(tǒng)計”的工具,可以幫我們把選中范圍的字?jǐn)?shù)、字符數(shù)統(tǒng)計出來。Linux下的wc命令可以實現(xiàn)這個 功能。使用vi打開文件的時候,底下的信息也會顯示行數(shù)和字節(jié)數(shù)。
(1)常用參數(shù)
格式:wc -l <file>
打印指定文件的文本行數(shù)。(l=小寫L)
以下參數(shù)可組合使用。
參數(shù):-c, --bytes
打印字節(jié)數(shù)(print the byte counts)
參數(shù):-m, --chars
打印字符數(shù)(print the character counts)
參數(shù):-l, --lines
打印行數(shù)(print the newline counts)
參數(shù):-L, --max-line-length
打印最長行的長度(print the length of the longest line)
參數(shù):-w, --words
打印單詞數(shù)(print the word counts)
(2)wc命令與 ls命令搭配使用
統(tǒng)計當(dāng)前文件夾下文件的個數(shù)
ls -l |grep "^-"|wc -l
統(tǒng)計當(dāng)前文件夾下目錄的個數(shù)
ls -l |grep "^d"|wc -l
統(tǒng)計當(dāng)前文件夾下文件的個數(shù),包括子文件夾里的
ls -lR|grep "^-"|wc -l
統(tǒng)計文件夾下目錄的個數(shù),包括子文件夾里的
ls -lR|grep "^d"|wc -l