安装(Windows/Linux/macOS)
Windows3种方式Chocolatey推荐choco install clocScoopscoop install cloc手动下载便携版无依赖Releases 页下载cloc-x.x.x.ziphttps://github.com/AlDanial/cloc/releases解压后把cloc.exe加入环境变量 PATH。Linux# Ubuntu/Debiansudo apt update sudo apt install cloc# CentOS/RHEL 8sudo dnf install cloc# Fedorasudo dnf install clocmacOS# Homebrew推荐brew install cloc# MacPortssudo port install cloc验证安装cloc --version二、核心用法高频命令1. 统计当前目录递归cloc .输出示例D:\Code\GitSrccloc-2.08.exe .61537 text files.59345 unique files.10905 files ignored.github.com/AlDanial/cloc v 2.08 T440.78 s (134.6 files/s, 38456.0 lines/s)----------------------------------------------------------------------------------------Language files blank comment code----------------------------------------------------------------------------------------C# 32645 859094 1614305 6114931SQL 14911 500764 334907 3632991JavaScript 5490 165789 222592 1627784XML 966 7638 20968 459256JSON 274 80 0 387787HTML 1579 23698 13296 275471CSS 400 17510 5224 140375MSBuild script 981 317 766 76952TypeScript 419 5831 11806 74321LESS 511 8761 3004 67279C# Designer 241 4439 17494 38356C 95 7586 5472 35740YAML 3 7164 0 27020Text 106 354 0 18439Properties 105 1648 5637 10708SCSS 119 654 197 8806C/C Header 107 2105 2466 8491Visual Studio Solution 44 43 44 6723SVG 54 3284 36 5878JSX 36 495 338 5750Ruby 1 3226 0 5242ASP.NET 17 450 105 4496Markdown 46 1419 1 4200C# Generated 7 1485 2390 3711Web Services Description 4 0 0 3426Windows Resource File 6 303 234 3190vim script 4 143 245 1961Visual Basic .NET 6 165 184 1719Python 14 388 1209 1443IDL 12 159 0 1367XSD 3 8 0 1037Razor 12 186 266 955ASP 8 155 0 804Velocity Template Language 14 46 73 611DOS Batch 45 159 53 562INI 11 19 0 522diff 13 40 308 491VBScript 3 51 35 443XSLT 2 32 2 320PowerShell 7 80 60 281Bourne Shell 12 56 38 247EJS 1 14 0 142TNSDL 2 0 0 87Thrift 1 16 414 65Perl 2 26 33 47NAnt script 2 0 14 46C 1 26 14 39Windows Module Definition 2 4 3 17PHP 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 --timeout0to your command line arguments. See the documentation onthe --timeout switch for more information.2. 排除目录必加如 node_modules、distcloc . --exclude-dirnode_modules,dist,build,venv,target3. 排除文件后缀cloc . --exclude-extlog,tmp,md4. 只统计指定语言cloc . --include-langPython,JavaScript,Java5. 按文件明细输出cloc src/ --by-file6. 输出 CSV/JSON用于报表# CSVcloc . --csv report.csv# JSONcloc . --json report.json7. 只统计 Git 跟踪文件忽略未提交文件cloc . --vcsgit三、常见问题与避坑不要用 pip install cloc这是同名 Python 包非官方 cloc装了无法运行。Windows 中文路径乱码运行前设置环境变量$env:PERL_UNICODES统计耗时过长必加--exclude-dirnode_modules,target否则大型项目