Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
467 views
in Technique[技术] by (71.8m points)

bash - 如何递归计算目录中的所有代码行?(How to count all the lines of code in a directory recursively?)

We've got a PHP application and want to count all the lines of code under a specific directory and its subdirectories.

(我们有一个PHP应用程序,并希望计算特定目录及其子目录下的所有代码行。)

We don't need to ignore comments, as we're just trying to get a rough idea.

(我们不需要忽略评论,因为我们只是想弄清楚。)

wc -l *.php 

That command works great within a given directory, but ignores subdirectories.

(该命令在给定目录中运行良好,但忽略子目录。)

I was thinking this might work, but it is returning 74, which is definitely not the case...

(我当时认为这可行,但它正在返回74,绝对不是这样......)

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

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

(提供所有文件的正确语法是什么?)

  ask by user77413 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try:

(尝试:)

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

The SLOCCount tool may help as well.

(SLOCCount工具也可能有所帮助。)

It'll give an accurate source lines of code count for whatever hierarchy you point it at, as well as some additional stats.

(它将为您指定的任何层次结构提供准确的源代码行数,以及一些其他统计信息。)

Sorted output: find . -name '*.php' | xargs wc -l | sort

(排序输出: find . -name '*.php' | xargs wc -l | sort) find . -name '*.php' | xargs wc -l | sort


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...