新闻  |   论坛  |   博客  |   在线研讨会
Linux统计项目代码行数-wc
电子禅石 | 2020-02-06 12:52:17    阅读:11260   发布文章

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


打开终端,用cd命令定位到工程所在的目录,然后调用以下命名即可把每个源代码文件行数及总数统计出来:

find . "(" -name "*.m" -or -name "*.mm" -or -name "*.cpp" -or -name "*.h" -or -name "*.rss" ")" -print | xargs wc -l

上面命令可以搜索这个工程。但包含了空格。

find . "(" -name "*c" -or -name "*.h" -or -name "*cpp" ")" -print | xargs wc -l

下面举几个例子:

1.统计当前目录下,py文件数量:

  1. find . -name "*.py" |wc -l

2.统计当前目录下,所有py文件行数:

  1. find . -name "*.py" |xargs cat|wc -l

3.统计当前目录下,所有py文件行数,并过滤空行:

  1. find . -name "*.py" |xargs cat|grep -v ^$|wc -l


*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
属于自己的技术积累分享,成为嵌入式系统研发高手。
推荐文章
最近访客