1. 打開終端;
2. 通過cd命令到達(dá)我們的工程文件岩榆,這里注意如果要避免統(tǒng)計(jì)引用的第三方庫(kù)的代碼量虑粥,我們就要進(jìn)一步進(jìn)到我們自己寫的代碼文件中去底哗,一般是一個(gè)與工程文件同名的文件;
3. 統(tǒng)計(jì)代碼行數(shù):
如果想列出每個(gè)文件的行數(shù)隧枫,輸入命令:
find?.?-name?"*.m"?-or?-name?"*.h"?-or?-name?"*.xib"?-or?-name?"*.c"?|xargs?wc?-l????
如果想直接列出總代碼行數(shù)喉磁,輸入命令:
find?.?-name?"*.m"?-or?-name?"*.h"?-or?-name?"*.xib"?-or?-name?"*.c"?|xargs?grep?-v?"^$"|wc?-l????
這樣就可以直接得出數(shù)量了,而且非彻倥В快协怒,是不是很方便~
這個(gè)統(tǒng)計(jì)過程會(huì)去掉空行,但注釋是會(huì)計(jì)算在內(nèi)的卑笨。
注:
Getting error “xargs unterminated quote” when tried to print the number of lines in terminal
Does one of your filenames have a quote in it? Try something like this:
find . "(" -name "*.m" -or -name "*.h" ")" -print0 | xargs -0 wc -l
The?-print0?argument tells?find?to use the NULL character to terminate each name that it prints out. The?-0?argument tells?xargs?that its input tokens are NULL-terminated. This avoids issues with characters that otherwise would be treated as special, like quotes.