如何计算源代码的行数

发布于 2024-10-09 05:34:45 字数 40 浏览 0 评论 0原文

正如标题所说,我如何使用 bash 命令计算源代码文件夹中的总行数

As the title says how i can calculate the total number of lines in a source code folder using bash commands

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

北方。的韩爷 2024-10-16 05:34:45

使用 sloccount

 “SLOCCount”,一组用于对潜在大量程序的多种语言中的物理源代码行数 (SLOC) 进行计数的工具

Use sloccount

 "SLOCCount", a set of tools for counting physical Source Lines of Code (SLOC) in a large number of languages of a potentially large set of programs

只是一片海 2024-10-16 05:34:45

你可以只使用

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

You can just use

find . -name '*.php' | xargs wc -l
司马昭之心 2024-10-16 05:34:45

使用 cloc。它支持大约 80 种语言。

Use cloc. It supports about 80 languages.

快乐很简单 2024-10-16 05:34:45

你可以尝试这样的事情:

find . -name "*.java" -exec cat {} \; | wc -l

You could try something like:

find . -name "*.java" -exec cat {} \; | wc -l
南烟 2024-10-16 05:34:45

我的建议是

  1. 使用 find 命令(如 Barti 的答案)来查找所有文件
  2. 使用 sed 或其他 删除所有注释
  3. 根本不要这样做

SLOC 是一种非常非常误导性的软件衡量方式。比尔·盖茨说,这就像通过重量来评估飞机的质量,这可能是他说过的唯一有帮助的话。

My suggestions would be

  1. Use a find command as in Barti's answer to locate all the files
  2. Use sed or something to strip out all the comments
  3. Don't do it at all

SLOC is a very, very misleading way to measure software. Bill Gates said it was like estimating the quality of an aircraft by weight, and it may be the only helpful thing he ever said.

衣神在巴黎 2024-10-16 05:34:45

这也会计算空行,但这很容易。转到您想要检查并执行的特定目录

find . | wc

This will count empty lines as well, but it's easy. Go to the specific directory you wanna check and do

find . | wc
勿忘初心 2024-10-16 05:34:45

已经得到了回答,只是提供了另一种使用 awk 的方法,您肯定会拥有。

猫 *.ext | awk 'BEGIN{i=0;} {i++;} END{print "Lines ", i}'

我也建议这样做,因为它可以很容易地编辑,为您想要的行添加模式(例如注释)不想数。

Already been answered, just giving another way using awk which you'll definitely have.

cat *.ext | awk 'BEGIN{i=0;} {i++;} END{print "Lines ", i}'

I only also suggest this because it can be easily edited to add patterns (such as comments) for lines that you don't want to count.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文