cloc
Count lines of code in files
TLDR
Count all the lines of code in a directory
Count all the lines of code in a directory, displaying a progress bar during the counting process
Compare 2 directory structures and count the differences between them
Ignore files that are ignored by VCS, such as files specified in .gitignore
Count all the lines of code in a directory, displaying the results for each file instead of each language
SYNOPSIS
cloc [options]
PARAMETERS
--by-file
Report results for each file.
--csv
Generate output in CSV format.
--report-file=
Write report to the specified file.
--exclude-dir=
Exclude the given directory from analysis.
--include-lang=
Include only files of the specified language. Can be used multiple times.
--follow-links
Follow symbolic links when traversing directories.
--help
Display help message.
--version
Display version information.
DESCRIPTION
cloc (Count Lines of Code) is a command-line utility that counts blank lines, comment lines, and physical lines of source code in multiple programming languages. It supports a wide variety of languages and file types. cloc is useful for understanding the size and complexity of software projects, tracking code growth over time, and identifying potential areas for improvement.
It operates by identifying file extensions and applying language-specific regular expressions to count the different types of lines. cloc is highly configurable, allowing users to exclude certain files or directories, specify custom file extensions, and generate reports in various formats. The tool provides a quick and efficient way to obtain basic metrics about a codebase without requiring any project-specific build processes or dependencies. It can be used to assess the effort required to maintain or modify the code. It is important to understand that cloc provides a statistical assessment, and other tools may be necessary for in depth analysis.
cloc requires Perl to run.
CAVEATS
cloc provides a statistical assessment of code size. It does not analyze the code's functionality or quality. The accuracy of line counts can be influenced by coding style and formatting.
OUTPUT INTERPRETATION
The output of cloc typically includes the following columns:
Language: The programming language of the analyzed files.
Files: The number of files of that language.
Blank: The number of blank lines.
Comment: The number of comment lines.
Code: The number of physical lines of code.
CUSTOM LANGUAGES
cloc can be extended to support custom file extensions or languages by modifying its internal language definition files. This allows users to analyze codebases that use non-standard naming conventions.
HISTORY
cloc was written by Al Danial. It has evolved over time to support more languages and reporting formats. It is widely used for software project analysis and management due to its simplicity and versatility.
SEE ALSO
wc(1)