使用wc統計代碼行數
阿新 • • 發佈:2018-01-24
... 當前 linu class 統計文件行數 代碼 fin pri cli
最近寫了一些代碼,想統計一下代碼的行數,在eclipse中好像沒這功能,網上搜了一下才發現原來Linux有一個統計文件行數的命令wc。使用wc可以打印出每個文件和總文件的行數、字數和字節數,如果沒有指定文件,則會讀取標準輸入(一般是終端)做統計。格式如下:
Usage: wc [OPTION]... [FILE]...
-c, --bytes, --chars print the byte counts
-l, --lines print the newline counts
-L, --max-line-length print the length of the longest line
-w, --words print the word counts
--help display this help and exit
--version output version information and exit
下面舉幾個例子:
1.統計當前目錄下,py文件數量:
find . -name "*.py" |wc -l
2.統計當前目錄下,所有py文件行數:
find . -name "*.py" |xargs cat|wc -l
3.統計當前目錄下,所有py文件行數,並過濾空行:
find . -name "*.py" |xargs cat|grep -v ^$|wc -l
使用wc統計代碼行數