cloc
source code line counter
TLDR
SYNOPSIS
cloc [options] file|directory|archive...
DESCRIPTION
cloc (Count Lines of Code) counts blank lines, comment lines, and physical lines of source code in over 200 programming languages. It analyzes individual files, entire directory trees, and compressed archives, producing summary reports broken down by language or by file.The tool includes a diff mode that compares two codebases and reports added, removed, modified, and unchanged lines. Output can be generated in plain text, CSV, JSON, SQL, or XML format for integration with other tools and reporting systems.Written in Perl with no external module dependencies, cloc is easy to install and runs on any platform with a Perl interpreter. It correctly handles multi-language files and uses language-specific comment detection rules for accurate counting. It can also operate on git repositories directly, comparing branches or commits.
PARAMETERS
--by-file
Report results per source file--by-file-by-lang
Report per file and per language--diff
Compare two code bases--csv
Output in CSV format--json
Output in JSON format--sql=file
Output as SQL insert statements--exclude-dir=list
Comma-separated directories to exclude--exclude-lang=list
Comma-separated languages to exclude--include-lang=list
Only count specified languages--include-ext=list
Only count files with the given comma-separated extensions.--max-file-size=MB
Skip files larger than MB megabytes (default: 100).--show-lang
List recognized languages and exit.--git
Forces inputs to be interpreted as git targets (commit hashes, branch names).--vcs=VCS
Use VCS to obtain list of files to count (e.g., git, svn).--xml
Output in XML format.--yaml
Output in YAML format.--quiet
Suppress progress output.--force-lang=LANG
Process all files with the given language counter.--config FILE
Read command-line switches from FILE instead of defaults.
OUTPUT FIELDS
Language, files, blank lines, comment lines, code lines
CAVEATS
Does not analyze semantic code complexity. Some edge cases in multi-language files may be miscounted. Requires Perl but has no external module dependencies. Supports over 250 programming languages.
HISTORY
cloc was created by Al Danial, first released on SourceForge and later moved to GitHub. It has become one of the most widely used open-source code counting tools.
