1. 打开终端;
2. 通过cd命令到达我们的工程文件,这里注意如果要避免统计引用的第三方库的代码量,我们就要进一步进到我们自己写的代码文件中去,一般是一个与工程文件同名的文件;
3. 统计代码行数:
如果想列出每个文件的行数,输入命令:
find . -name "*.m" -or -name "*.h" -or -name "*.xib" -or -name "*.c" |xargs wc -l
如果想直接列出总代码行数,输入命令:
find . -name "*.m" -or -name "*.h" -or -name "*.xib" -or -name "*.c" |xargs grep -v "^$"|wc -l
这样就可以直接得出数量了,而且非常快,是不是很方便~
这个统计过程会去掉空行,但注释是会计算在内的。
注:
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.
网友评论