三種在MacOS終端下獲取源程序量方法:
1、打開終端。
2、cd到你項目的路徑。(cd+空格+文件路徑)
3、輸入如下命令:
(a)
統計整個工程的所有文件的代碼量以及總量
find . "(" -name "*.m" -or -name "*.mm" -or -name "*.cpp" -or -name "*.h" -or -name "*.rss" ")" -print | xargs wc -l
(b)
find . -name '*.m' -exec cat {} \; | wc -l
find . -name '*.h' -exec cat {} \; | wc -l
(c)
grep -d recurse "\n" classes| wc -l
上面classes是你代碼的存放路徑,如果你不是默認的Classes路徑,改之。
==================
e.g.文件目錄如下:
folder ABC:
-test.plist
-ABC.xcodeproj
-folder ABC:
-folder classes
-other files
bash命令:
bogon:~ apple$ cd /Users/apple/Work/ABC
bogon:ABC apple$ grep -d recurse "\n" ABC/classes| wc -l
55097
bogon:ABC apple$
列出代碼行數總和:
find . -name "*.m" -or -name "*.h" -or -name "*.xib" -or -name "*.c" |xargs grep -v "^$"|wc -l
grep -v "^$"是去掉空行
注釋也統計在代碼量之內,畢竟也一個字一個字碼出來的