





















cloc(Count Lines of Code) 是一个跨平台、开源的代码行统计工具,用 Perl 编写,可统计空行、注释行、有效代码行,支持超 200 种编程语言,能递归扫描目录、排除指定文件夹/后缀、按语言分类输出。
choco install cloc
scoop install cloc
cloc-x.x.x.zip:https://github.com/AlDanial/cloc/releasescloc.exe 加入环境变量 PATH。
# Ubuntu/Debian
sudo apt update && sudo apt install cloc
# CentOS/RHEL 8+
sudo dnf install cloc
# Fedora
sudo dnf install cloc
# Homebrew(推荐)
brew install cloc
# MacPorts
sudo port install cloc
cloc --version
cloc .
输出示例:
D:\Code\GitSrc>cloc-2.08.exe .
61537 text files.
59345 unique files.
10905 files ignored.
github.com/AlDanial/cloc v 2.08 T=440.78 s (134.6 files/s, 38456.0 lines/s)
----------------------------------------------------------------------------------------
Language files blank comment code
----------------------------------------------------------------------------------------
C# 32645 859094 1614305 6114931
SQL 14911 500764 334907 3632991
JavaScript 5490 165789 222592 1627784
XML 966 7638 20968 459256
JSON 274 80 0 387787
HTML 1579 23698 13296 275471
CSS 400 17510 5224 140375
MSBuild script 981 317 766 76952
TypeScript 419 5831 11806 74321
LESS 511 8761 3004 67279
C# Designer 241 4439 17494 38356
C++ 95 7586 5472 35740
YAML 3 7164 0 27020
Text 106 354 0 18439
Properties 105 1648 5637 10708
SCSS 119 654 197 8806
C/C++ Header 107 2105 2466 8491
Visual Studio Solution 44 43 44 6723
SVG 54 3284 36 5878
JSX 36 495 338 5750
Ruby 1 3226 0 5242
ASP.NET 17 450 105 4496
Markdown 46 1419 1 4200
C# Generated 7 1485 2390 3711
Web Services Description 4 0 0 3426
Windows Resource File 6 303 234 3190
vim script 4 143 245 1961
Visual Basic .NET 6 165 184 1719
Python 14 388 1209 1443
IDL 12 159 0 1367
XSD 3 8 0 1037
Razor 12 186 266 955
ASP 8 155 0 804
Velocity Template Language 14 46 73 611
DOS Batch 45 159 53 562
INI 11 19 0 522
diff 13 40 308 491
VBScript 3 51 35 443
XSLT 2 32 2 320
PowerShell 7 80 60 281
Bourne Shell 12 56 38 247
EJS 1 14 0 142
TNSDL 2 0 0 87
Thrift 1 16 414 65
Perl 2 26 33 47
NAnt script 2 0 14 46
C 1 26 14 39
Windows Module Definition 2 4 3 17
PHP 1 0 0 3
----------------------------------------------------------------------------------------
SUM: 59345 1625910 2264233 13060532
----------------------------------------------------------------------------------------
One or more files took longer to process than expected.
Try rerunning without timeout guards by adding --timeout=0
to your command line arguments. See the documentation on
the --timeout switch for more information.
cloc . --exclude-dir=node_modules,dist,build,venv,target
cloc . --exclude-ext=log,tmp,md
cloc . --include-lang=Python,JavaScript,Java
cloc src/ --by-file
# CSV
cloc . --csv > report.csv
# JSON
cloc . --json > report.json
cloc . --vcs=git
$env:PERL_UNICODE="S"
--exclude-dir=node_modules,target,否则大型项目会卡死。cloc --show-lang
cloc 是零依赖、跨平台、高精度的代码统计神器,核心命令就 3 个:安装→基础统计→排除目录。前端/后端/移动端项目通用,适合做代码规模评估、技术债治理、团队绩效参考。
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。