如何递归计算目录中的所有代码行? [英] How can I count all the lines of code in a directory recursively?

查看:53
本文介绍了如何递归计算目录中的所有代码行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个PHP应用程序,想要统计特定目录及其子目录下的所有代码行.我们不需要忽略评论,因为我们只是想获得一个大概的想法.

We've got a PHP application and want to count all the lines of code under a specific directory and its subdirectories. We don't need to ignore comments, as we're just trying to get a rough idea.

wc -l *.php 

该命令在给定目录中效果很好,但是会忽略子目录.我以为这可能行得通,但返回74,绝对不是这种情况...

That command works great within a given directory, but it ignores subdirectories. I was thinking this might work, but it is returning 74, which is definitely not the case...

find . -name '*.php' | wc -l

输入所有文件的正确语法是什么?

What's the correct syntax to feed in all the files?

推荐答案

您可以使用 cloc 实用程序.它报告每种语言的行数,以及注释的行数等.CLOC在Linux,Mac和Windows上可用.

You can use the cloc utility which is built for this exact purpose. It reports each the amount of lines in each language, together with how many of them are comments, etc. CLOC is available on Linux, Mac and Windows.

用法和输出示例:

$ cloc --exclude-lang=DTD,Lua,make,Python .
    2570 text files.
    2200 unique files.
    8654 files ignored.

http://cloc.sourceforge.net v 1.53  T=8.0 s (202.4 files/s, 99198.6 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
JavaScript                    1506          77848         212000         366495
CSS                             56           9671          20147          87695
HTML                            51           1409            151           7480
XML                              6           3088           1383           6222
-------------------------------------------------------------------------------
SUM:                          1619          92016         233681         467892
-------------------------------------------------------------------------------

这篇关于如何递归计算目录中的所有代码行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆