https://github.com/AlDanial/cloc
cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.
https://github.com/AlDanial/cloc
cloc count-lines programming-language
Last synced: about 1 year ago
JSON representation
cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.
- Host: GitHub
- URL: https://github.com/AlDanial/cloc
- Owner: AlDanial
- License: gpl-2.0
- Created: 2015-09-07T03:30:43.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-10-24T03:30:06.000Z (over 1 year ago)
- Last Synced: 2024-10-30T01:39:23.627Z (over 1 year ago)
- Topics: cloc, count-lines, programming-language
- Language: Perl
- Size: 4.91 MB
- Stars: 19,550
- Watchers: 214
- Forks: 1,021
- Open Issues: 25
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-tools - cloc - 代码统计工具。 (Development / Time Series)
- awesome-alternatives-in-rust - cloc
- fucking-Awesome-Linux-Software - ](https://github.com/AlDanial/cloc)
[](https://github.com/AlDanial/cloc/graphs/contributors)
[](https://doi.org/10.5281/zenodo.42029482)
[](https://github.com/AlDanial/cloc/network/members)
[]()
cloc moved to GitHub in September 2015 after being hosted
at http://cloc.sourceforge.net/ since August 2006.
* [Quick Start](#quick-start-)
* [Overview](#overview-)
* [Download](https://github.com/AlDanial/cloc/releases/latest)
* [Install via package manager](#install-via-package-manager)
* [Stable release](#stable-release)
* [Development version](#development-version)
* [License](#license-)
* [Why Use cloc?](#why-use-cloc-)
* [Other Counters](#other-counters-)
* [Building a Windows Executable](#building-a-windows-executable-)
* [Basic Use](#basic-use-)
* [Options](#options-)
* [Recognized Languages](#recognized-languages-)
* [How it Works](#how-it-works-)
* [Advanced Use](#advanced-use-)
* [Remove Comments from Source Code](#remove-comments-from-source-code-)
* [Work with Compressed Archives](#work-with-compressed-archives-)
* [Differences](#differences-)
* [Create Custom Language Definitions](#create-custom-language-definitions-)
* [Combine Reports](#combine-reports-)
* [SQL](#sql-)
* [Custom Column Output](#custom-column-output-)
* [Wrapping cloc in other scripts](#wrapping-cloc-in-other-scripts-)
* [git and UTF8 pathnames](#git-and-UTF8-pathnames-)
* [Third Generation Language Scale Factors](#third-generation-language-scale-factors-)
* [options.txt configuration file](#optionstxt-configuration-file-)
* [Java Programmatic Interface](#java-programmatic-interface-)
* [Complex regular subexpression recursion limit ](#complex-regular-subexpression-recursion-limit-)
* [Limitations](#limitations-)
* [Requesting Support for Additional Languages](#requesting-support-for-additional-languages-)
* [Reporting Problems](#reporting-problems-)
* [Citation](#citation-)
* [Acknowledgments](#acknowledgments-)
* [Copyright](#copyright-)
[]({{{1)
# [Quick Start ▲](#___top "click to go to top of document")
Step 1: Download cloc (several methods, see below) or run cloc's
[docker image](#run-via-docker). The Windows executable has no requirements.
The source version of cloc requires a Perl interpreter, and the
Docker version of cloc requires a Docker installation.
Step 2: Open a terminal (`cmd.exe` on Windows).
Step 3: Invoke cloc to count your source files, directories, archives,
or git commits.
The executable name differs depending on whether you use the
development source version (`cloc`), source for a
released version (`cloc-2.04.pl`) or a Windows executable
(`cloc-2.04.exe`).
On this page, `cloc` is the generic term
used to refer to any of these.
[Include Security](https://www.youtube.com/user/IncludeSecurity) has a
[YouTube video](https://www.youtube.com/watch?v=eRLTkDMsCqs)
showing the steps in action.
**a file**
prompt> cloc hello.c
1 text file.
1 unique file.
0 files ignored.
https://github.com/AlDanial/cloc v 1.65 T=0.04 s (28.3 files/s, 340.0 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
C 1 0 7 5
-------------------------------------------------------------------------------
**a directory**
prompt> cloc gcc-5.2.0/gcc/c
16 text files.
15 unique files.
3 files ignored.
https://github.com/AlDanial/cloc v 1.65 T=0.23 s (57.1 files/s, 188914.0 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
C 10 4680 6621 30812
C/C++ Header 3 99 286 496
-------------------------------------------------------------------------------
SUM: 13 4779 6907 31308
-------------------------------------------------------------------------------
**an archive**
We'll pull cloc's source zip file from GitHub, then count the contents:
prompt> wget https://github.com/AlDanial/cloc/archive/master.zip
prompt> cloc master.zip
https://github.com/AlDanial/cloc v 1.65 T=0.07 s (26.8 files/s, 141370.3 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Perl 2 725 1103 8713
-------------------------------------------------------------------------------
SUM: 2 725 1103 8713
-------------------------------------------------------------------------------
**a git repository, using a specific commit**
This example uses code from
PuDB, a fantastic Python debugger.
prompt> git clone https://github.com/inducer/pudb.git
prompt> cd pudb
prompt> cloc 6be804e07a5db
48 text files.
41 unique files.
8 files ignored.
github.com/AlDanial/cloc v 1.99 T=0.04 s (1054.9 files/s, 189646.8 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Python 28 1519 728 4659
reStructuredText 6 102 20 203
YAML 2 9 2 75
Bourne Shell 3 6 0 17
Text 1 0 0 11
make 1 4 6 10
-------------------------------------------------------------------------------
SUM: 41 1640 756 4975
-------------------------------------------------------------------------------
**each subdirectory of a particular directory**
Say you have a directory with three different git-managed projects,
Project0, Project1, and Project2. You can use your shell's looping
capability to count the code in each. This example uses bash (scroll down for cmd.exe example):
prompt> for d in ./*/ ; do (cd "$d" && echo "$d" && cloc --vcs git); done
./Project0/
7 text files.
7 unique files.
1 file ignored.
github.com/AlDanial/cloc v 1.71 T=0.02 s (390.2 files/s, 25687.6 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
D 4 61 32 251
Markdown 1 9 0 38
make 1 0 0 4
-------------------------------------------------------------------------------
SUM: 6 70 32 293
-------------------------------------------------------------------------------
./Project1/
7 text files.
7 unique files.
0 files ignored.
github.com/AlDanial/cloc v 1.71 T=0.02 s (293.0 files/s, 52107.1 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Go 7 165 282 798
-------------------------------------------------------------------------------
SUM: 7 165 282 798
-------------------------------------------------------------------------------
./Project2/
49 text files.
47 unique files.
13 files ignored.
github.com/AlDanial/cloc v 1.71 T=0.10 s (399.5 files/s, 70409.4 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Python 33 1226 1026 3017
C 4 327 337 888
Markdown 1 11 0 28
YAML 1 0 2 12
-------------------------------------------------------------------------------
SUM: 39 1564 1365 3945
-------------------------------------------------------------------------------
**each subdirectory of a particular directory (Windows/cmd.exe)**
for /D %I in (.\*) do cd %I && cloc --vcs git && cd ..
[](1}}})
[]({{{1)
# [Overview ▲](#___top "click to go to top of document")
cloc counts blank lines, comment lines, and physical lines of source
code in [many programming languages](#Languages). Given two versions of
a code base, cloc can compute differences in blank, comment, and source
lines. It is written entirely in Perl with no dependencies outside the
standard distribution of Perl v5.6 and higher (code from some external
modules is [embedded within
cloc](https://github.com/AlDanial/cloc#regexp_common)) and so is
quite portable. cloc is known to run on many flavors of Linux, FreeBSD,
NetBSD, OpenBSD, macOS, AIX, HP-UX, Solaris, IRIX, z/OS, and Windows.
(To run the Perl source version of cloc on Windows one needs
[ActiveState Perl](http://www.activestate.com/activeperl) 5.6.1 or
higher, [Strawberry Perl](http://strawberryperl.com/),
Windows Subsystem for Linux,
[Cygwin](http://www.cygwin.com/),
[MobaXTerm](http://mobaxterm.mobatek.net/) with the Perl plug-in
installed,
or
a mingw environment and terminal such as provided by
[Git for Windows](https://gitforwindows.org/).
Alternatively one can use the Windows binary of cloc
generated with [PAR::Packer](http://search.cpan.org/~rschupp/PAR-Packer-1.019/lib/pp.pm)
to run on Windows computers that have neither Perl nor Cygwin.)
In addition to counting code in individual text files, directories,
and git repositories, cloc can also count code in archive files such
as ``.tar`` (including compressed versions), ``.zip``, Python
wheel ``.whl``, Jupyter notebook ``.ipynb``, source RPMs ``.rpm``
or ``.src`` (requires ``rpm2cpio``),
and Debian ``.deb`` files (requires ``dpkg-deb``).
cloc contains code from David Wheeler's
[SLOCCount](http://www.dwheeler.com/sloccount/),
Damian Conway and Abigail's Perl module
[Regexp::Common](http://search.cpan.org/%7Eabigail/Regexp-Common-2.120/lib/Regexp/Common.pm),
Sean M. Burke's Perl module
[Win32::Autoglob](http://search.cpan.org/%7Esburke/Win32-Autoglob-1.01/Autoglob.pm),
and Tye McQueen's Perl module
[Algorithm::Diff](http://search.cpan.org/%7Etyemq/Algorithm-Diff-1.1902/lib/Algorithm/Diff.pm).
Language scale factors were derived from Mayes Consulting, LLC web site
http://softwareestimator.com/IndustryData2.htm.
New releases nominally appear every six months.
[](1}}})
These docker commands count lines of code in and below
the current directory:
```shell
docker run --rm -v $PWD:/tmp aldanial/cloc .
```
### Run via docker on git-bash
```shell
docker run --rm -v "/$(pwd -W)":/tmp aldanial/cloc .
```
## Install via package manager
Depending your operating system, one of these installation methods may
work for you (all but the last two entries for Windows require
a Perl interpreter):
npm install -g cloc # https://www.npmjs.com/package/cloc
sudo apt install cloc # Debian, Ubuntu
sudo yum install cloc # Red Hat, Fedora
sudo dnf install cloc # Fedora 22 or later
sudo pacman -S cloc # Arch
yay -S cloc-git # Arch AUR (latest git version)
sudo emerge -av dev-util/cloc # Gentoo https://packages.gentoo.org/packages/dev-util/cloc
sudo apk add cloc # Alpine Linux
doas pkg_add cloc # OpenBSD
sudo pkg install cloc # FreeBSD
sudo port install cloc # macOS with MacPorts
brew install cloc # macOS with Homebrew
winget install AlDanial.Cloc # Windows with winget (might not work, ref https://github.com/AlDanial/cloc/issues/849)
choco install cloc # Windows with Chocolatey
scoop install cloc # Windows with Scoop
**Note**: I don't control any of these packages.
If you encounter a bug in cloc using one of the above
packages, try with cloc pulled from the latest stable release here
on GitHub (link follows below) before submitting a problem report.
[](1}}})
[]({{{1)
## Stable release
Download the latest released cloc source file, for example `cloc-2.04.pl`, or
the Windows executable `cloc-2.04.exe` from
https://github.com/AlDanial/cloc/releases/latest
Download the cloc source code at https://github.com/AlDanial/cloc/raw/master/cloc and
save it as the file `cloc` (or `cloc.pl`, or whatever executable name you wish).
The next step depends on the operating system you're using.
### On Unix-like systems, including macOS
In a terminal, go to the download directory
and make the cloc file executable, then give it a test run.
For example
```shell
» cd ~/Downloads
» chmod +x cloc
» ./cloc --version
```
For future use, move the file to a more convenient directory in your `PATH`
such as `/usr/local/bin` or `~/bin`.
### On Windows
You'll need a Perl interpreter such as [Strawberry Perl](http://strawberryperl.com/)
installed to run the source version of cloc.
After downloading the cloc source file, open a command prompt or PowerShell window,
navigate to the download directory (`C:\TEMP` in the example below), then test cloc with:
```dos
cd C:\TEMP>
C:TEMP\> perl cloc --version
```
[](1}}})
[]({{{1)
# [License ▲](#___top "click to go to top of document")
cloc is licensed under the
[GNU General Public License, v 2](http://www.gnu.org/licenses/gpl-2.0.html),
excluding portions which
are copied from other sources. Code
copied from the Regexp::Common, Win32::Autoglob, and Algorithm::Diff
Perl modules is subject to the
[Artistic License](https://opensource.org/license/artistic-2-0).
[](1}}})
[]({{{1)
# [Why Use cloc? ▲](#___top "click to go to top of document")
cloc has many features that make it easy to use, thorough, extensible, and portable:
1. Exists as a single, self-contained file that requires minimal installation effort---just download the file and run it.
2. Can read language comment definitions from a file and thus potentially work with computer languages that do not yet exist.
3. Allows results from multiple runs to be summed together by language and by project.
4. Can produce results in a variety of formats: plain text, Markdown, SQL, JSON, XML, YAML, comma separated values.
5. Can count code within compressed archives (tar balls, Zip files, Java .ear files).
6. Has numerous troubleshooting options.
7. Handles file and directory names with spaces and other unusual characters.
8. Has no dependencies outside the standard Perl distribution.
9. Runs on Linux, FreeBSD, NetBSD, OpenBSD, macOS, AIX, HP-UX, Solaris, IRIX, and z/OS systems that have Perl 5.6 or higher. The source version runs on Windows with either ActiveState Perl, Strawberry Perl, Cygwin, or MobaXTerm+Perl plugin. Alternatively on Windows one can run the Windows binary which has no dependencies.
[](1}}})
[]({{{1)
# [Other Counters ▲](#___top "click to go to top of document")
If cloc does not suit your needs here are other freely available counters to consider:
* [loc](https://github.com/cgag/loc/)
* [gcloc](https://github.com/JoaoDanielRufino/gcloc)
* [gocloc](https://github.com/hhatto/gocloc/)
* [Ohcount](https://github.com/blackducksoftware/ohcount/)
* [scc](https://github.com/boyter/scc/)
* [sclc](https://code.google.com/archive/p/sclc/)
* [SLOCCount](http://www.dwheeler.com/sloccount/)
* [Sonar](http://www.sonarsource.org/)
* [tokei](https://github.com/Aaronepower/tokei/)
* [Unified Code Count](http://csse.usc.edu/ucc_new/wordpress/)
Other references:
* QSM's [directory](http://www.qsm.com/CodeCounters.html) of code counting tools.
* The [Wikipedia entry](http://en.wikipedia.org/wiki/Source_lines_of_code) for source code line counts.
[](1}}})
# Regexp::Common, Digest::MD5, Win32::Autoglob, Algorithm::Diff []({{{1)
Although cloc does not need Perl modules outside those found in the
standard distribution, cloc does rely on a few external modules. Code
from three of these external modules--Regexp::Common, Win32::Autoglob,
and Algorithm::Diff--is embedded within cloc. A fourth module,
Digest::MD5, is used only if it is available. If cloc finds
Regexp::Common or Algorithm::Diff installed locally it will use those
installation. If it doesn't, cloc will install the parts of
Regexp::Common and/or Algorithm:Diff it needs to temporary directories
that are created at the start of a cloc run then removed when the run is
complete. The necessary code from Regexp::Common v2.120 and
Algorithm::Diff v1.1902 are embedded within the cloc source code (see
subroutines `Install_Regexp_Common()` and `Install_Algorithm_Diff()` ).
Only three lines are needed from Win32::Autoglob and these are included
directly in cloc.
Additionally, cloc will use Digest::MD5 to validate uniqueness among
equally-sized input files if Digest::MD5 is installed locally.
A parallel processing option, --processes=N, was introduced with
cloc version 1.76 to enable faster runs on multi-core machines. However,
to use it, one must have the module Parallel::ForkManager installed.
This module does not work reliably on Windows so parallel processing
will only work on Unix-like operating systems.
The Windows binary is built on a computer that has both Regexp::Common
and Digest::MD5 installed locally.
[](1}}})
[]({{{1)
# [Building a Windows Executable ▲](#___top "click to go to top of document")
#### Create your own executable
The most robust option for creating a Windows executable of
cloc is to use [ActiveState's Perl Development Kit](http://www.activestate.com/perl-dev-kit).
It includes a utility, `perlapp`, which can build stand-alone
Windows, Mac, and Linux binaries of Perl source code.
[perl2exe](http://www.indigostar.com/perl2exe/)
will also do the trick. If you do have `perl2exe`, modify lines
84-87 in the cloc source code for a minor code
modification that is necessary to make a cloc Windows executable.
Otherwise, to build a Windows executable with `pp` from
`PAR::Packer`, first install a Windows-based Perl distribution
(for example Strawberry Perl or ActivePerl) following their
instructions. Next, open a command prompt, aka a DOS window and install
the PAR::Packer module. Finally, invoke the newly installed `pp`
command with the cloc source code to create an `.exe` file:
C:> cpan -i Digest::MD5
C:> cpan -i Regexp::Common
C:> cpan -i Algorithm::Diff
C:> cpan -i PAR::Packer
C:> cpan -i Win32::LongPath
C:> pp -M Win32::LongPath -M Encode::Unicode -M Digest::MD5 -c -x -o cloc-2.04.exe cloc-2.04.pl
A variation on the instructions above is if you installed the portable
version of Strawberry Perl, you will need to run `portableshell.bat` first
to properly set up your environment.
The Windows executable in the Releases section, cloc-2.04.exe,
was built on a 64 bit Windows 10 computer using
[Strawberry Perl](http://strawberryperl.com/)
5.30.2 and
[PAR::Packer](http://search.cpan.org/~rschupp/PAR-Packer-1.050/lib/pp.pm)
to build the `.exe`.
#### Is the Windows executable safe to run? Does it have malware?
Ideally, no one would need the Windows executable because they
have a Perl interpreter installed on their machines and can
run the cloc source file.
On centrally-managed corporate Windows machines, however, this
this may be difficult or impossible.
The Windows executable distributed with cloc is provided as
a best-effort of a virus and malware-free `.exe`.
You are encouraged to run your own virus scanners against the
executable and also check sites such
https://www.virustotal.com/ .
The entries for recent versions are:
cloc-2.04.exe:
https://www.virustotal.com/gui/file/89cda0038bf4e13c6c13ebc1e60bec4dfad362e69ac8a5b8e2d5ebe3020359e1
cloc-2.02-winget.exe: (includes [PR 850](https://github.com/AlDanial/cloc/pull/850) to allow
[running from a symlink on Windows](https://github.com/AlDanial/cloc/issues/849))
https://www.virustotal.com/gui/file/be033061e091fea48a5bc9e8964cee0416ddd5b34bd5226a1c9aa4b30bdba66a?nocache=1
cloc-2.02.exe:
https://www.virustotal.com/gui/file/369ed76125f7399cd582d169adf39a2e08ae5066031fea0cc8b2836ea50e7ce2?nocache=1
cloc-2.00.exe:
https://www.virustotal.com/gui/file/7a234ef0cb495de1b5776acf88c5554e2bab1fb02725a5fb85756a6db3121c1f
cloc-1.98.exe:
https://www.virustotal.com/gui/file/88615d193ec8c06f7ceec3cc1d661088af997798d87ddff331d9e9f9128a6782?nocache=1
cloc-1.96.1.exe:
https://www.virustotal.com/gui/file/00b1c9dbbfb920dabd374418e1b86d2c24b8cd2b8705aeb956dee910d0d75d45?nocache=1
cloc-1.96.exe:
https://www.virustotal.com/gui/file/54bf5f46fbaba7949c4eb2d4837b03c774c0ba587448a5bad9b8efc0222b1583?nocache=1
cloc-1.94.exe:
https://www.virustotal.com/gui/file/b48a6002fb75fa66ec5d0c05a5c4d51f2ad22b5b025b7eb4e3945d18419c0952?nocache=1
cloc-1.92.exe:
https://www.virustotal.com/gui/file/2668fcf8609c431e8934fe9e1866bc620c58d198c4eb262f1d3ef31ef4a690f7
cloc-1.90.exe:
https://www.virustotal.com/gui/file/d655caae55486f9bac39f7e3c7b7553bcfcfe2b88914c79bfc328055f22b8a37/detection
cloc-1.88.exe:
https://www.virustotal.com/gui/file/97d5d2631d1cccdbfd99267ab8a4cf5968816bbe52c0f9324e72e768857f642d/detection
cloc-1.86.exe:
https://www.virustotal.com/gui/file/1b2e189df1834411b34534db446330d1c379b4bc008af3042ee9ade818c6a1c8/detection
cloc-1.84.exe:
https://www.virustotal.com/gui/file/e73d490c1e4ae2f50ee174005614029b4fa2610dcb76988714839d7be68479af/detection
cloc-1.82.exe:
https://www.virustotal.com/#/file/2e5fb443fdefd776d7b6b136a25e5ee2048991e735042897dbd0bf92efb16563/detection
cloc-1.80.exe:
https://www.virustotal.com/#/file/9e547b01c946aa818ffad43b9ebaf05d3da08ed6ca876ef2b6847be3bf1cf8be/detection
cloc-1.78.exe:
https://www.virustotal.com/#/file/256ade3df82fa92febf2553853ed1106d96c604794606e86efd00d55664dd44f/detection
cloc-1.76.exe:
https://www.virustotal.com/#/url/c1b9b9fe909f91429f95d41e9a9928ab7c58b21351b3acd4249def2a61acd39d/detection
cloc-1.74_x86.exe:
https://www.virustotal.com/#/file/b73dece71f6d3199d90d55db53a588e1393c8dbf84231a7e1be2ce3c5a0ec75b/detection
cloc 1.72 exe:
https://www.virustotal.com/en/url/8fd2af5cd972f648d7a2d7917bc202492012484c3a6f0b48c8fd60a8d395c98c/analysis/
cloc 1.70 exe:
https://www.virustotal.com/en/url/63edef209099a93aa0be1a220dc7c4c7ed045064d801e6d5daa84ee624fc0b4a/analysis/
cloc 1.68 exe:
https://www.virustotal.com/en/file/c484fc58615fc3b0d5569b9063ec1532980281c3155e4a19099b11ef1c24443b/analysis/
cloc 1.66 exe:
https://www.virustotal.com/en/file/54d6662e59b04be793dd10fa5e5edf7747cf0c0cc32f71eb67a3cf8e7a171d81/analysis/1453601367/
#### Why is the Windows executable so large?
Windows executables of cloc versions 1.60 and earlier, created with
perl2exe as noted above, are about 1.6 MB, while versions 1.62 and 1.54, created
with `PAR::Packer`, are 11 MB.
Version 1.66, built with a newer version of `PAR::Packer`, is about 5.5 MB.
Why are the `PAR::Packer`, executables so
much larger than those built with perl2exe? My theory is that perl2exe
uses smarter tree pruning logic
than `PAR::Packer`, but that's pure speculation.
[](1}}})
[]({{{1)
# [Basic Use ▲](#___top "click to go to top of document")
cloc is a command line program that takes file, directory, and/or
archive names as inputs. Here's an example of running cloc against the
Perl v5.22.0 source distribution:
prompt> cloc perl-5.22.0.tar.gz
5605 text files.
5386 unique files.
2176 files ignored.
https://github.com/AlDanial/cloc v 1.65 T=25.49 s (134.7 files/s, 51980.3 lines/s)
-----------------------------------------------------------------------------------
Language files blank comment code
-----------------------------------------------------------------------------------
Perl 2892 136396 184362 536445
C 130 24676 33684 155648
C/C++ Header 148 9766 16569 147858
Bourne Shell 112 4044 6796 42668
Pascal 8 458 1603 8592
XML 33 142 0 2410
YAML 49 20 15 2078
C++ 10 313 277 2033
make 4 426 488 1986
Prolog 12 438 2 1146
JSON 14 1 0 1037
yacc 1 85 76 998
Windows Message File 1 102 11 489
DOS Batch 14 92 41 389
Windows Resource File 3 10 0 85
D 1 5 7 8
Lisp 2 0 3 4
-----------------------------------------------------------------------------------
SUM: 3434 176974 243934 903874
-----------------------------------------------------------------------------------
To run cloc on Windows computers, open up a command (aka DOS) window
and invoke cloc.exe from the command line there.
Alternatively, try ClocViewer, the GUI wrapper around cloc found at
https://github.com/Roemer/ClocViewer.
See also https://github.com/jmensch1/codeflower for a
graphical rendering of cloc results.
[](1}}})
[]({{{1)
# [Options ▲](#___top "click to go to top of document")
prompt> cloc --help
Usage: cloc [options] <file(s)/dir(s)/git hash(es)> | <set 1> <set 2> | <report files>
Count, or compute differences of, physical lines of source code in the
given files (may be archives such as compressed tarballs or zip files,
or git commit hashes or branch names) and/or recursively below the
given directories.
Input Options
--extract-with=<cmd> This option is only needed if cloc is unable
to figure out how to extract the contents of
the input file(s) by itself.
Use <cmd> to extract binary archive files (e.g.:
.tar.gz, .zip, .Z). Use the literal '>FILE<' as
a stand-in for the actual file(s) to be
extracted. For example, to count lines of code
in the input files
gcc-4.2.tar.gz perl-5.8.8.tar.gz
on Unix use
--extract-with='gzip -dc >FILE< | tar xf -'
or, if you have GNU tar,
--extract-with='tar zxf >FILE<'
and on Windows use, for example:
--extract-with="\"c:\Program Files\WinZip\WinZip32.exe\" -e -o >FILE< ."
(if WinZip is installed there).
--list-file=<file> Take the list of file and/or directory names to
process from <file>, which has one file/directory
name per line. Only exact matches are counted;
relative path names will be resolved starting from
the directory where cloc is invoked. Set <file>
to - to read file names from a STDIN pipe.
See also --exclude-list-file.
--diff-list-file=<file> Take the pairs of file names to be diff'ed from
<file>, whose format matches the output of
--diff-alignment. (Run with that option to
see a sample.) The language identifier at the
end of each line is ignored. This enables --diff
mode and bypasses file pair alignment logic.
--vcs=<VCS> Invoke a system call to <VCS> to obtain a list of
files to work on. If <VCS> is 'git', then will
invoke 'git ls-files' to get a file list and
'git submodule status' to get a list of submodules
whose contents will be ignored. See also --git
which accepts git commit hashes and branch names.
If <VCS> is 'svn' then will invoke 'svn list -R'.
The primary benefit is that cloc will then skip
files explicitly excluded by the versioning tool
in question, ie, those in .gitignore or have the
svn:ignore property.
Alternatively <VCS> may be any system command
that generates a list of files.
Note: cloc must be in a directory which can read
the files as they are returned by <VCS>. cloc will
not download files from remote repositories.
'svn list -R' may refer to a remote repository
to obtain file names (and therefore may require
authentication to the remote repository), but
the files themselves must be local.
Setting <VCS> to 'auto' selects between 'git'
and 'svn' (or neither) depending on the presence
of a .git or .svn subdirectory below the directory
where cloc is invoked.
--unicode Check binary files to see if they contain Unicode
expanded ASCII text. This causes performance to
drop noticeably.
Processing Options
--autoconf Count .in files (as processed by GNU autoconf) of
recognized languages. See also --no-autogen.
--by-file Report results for every source file encountered.
--by-file-by-lang Report results for every source file encountered
in addition to reporting by language.
--config <file> Read command line switches from <file> instead of
the default location of /home/al/.config/cloc/options.txt.
The file should contain one switch, along with
arguments (if any), per line. Blank lines and lines
beginning with '#' are skipped. Options given on
the command line take priority over entries read from
the file.
--count-and-diff <set1> <set2>
First perform direct code counts of source file(s)
of <set1> and <set2> separately, then perform a diff
of these. Inputs may be pairs of files, directories,
or archives. If --out or --report-file is given,
three output files will be created, one for each
of the two counts and one for the diff. See also
--diff, --diff-alignment, --diff-timeout,
--ignore-case, --ignore-whitespace.
--diff <set1> <set2> Compute differences in code and comments between
source file(s) of <set1> and <set2>. The inputs
may be any mix of files, directories, archives,
or git commit hashes. Use --diff-alignment to
generate a list showing which file pairs where
compared. When comparing git branches, only files
which have changed in either commit are compared.
See also --git, --count-and-diff, --diff-alignment,
--diff-list-file, --diff-timeout, --ignore-case,
--ignore-whitespace.
--diff-timeout <N> Ignore files which take more than <N> seconds
to process. Default is 10 seconds. Setting <N>
to 0 allows unlimited time. (Large files with many
repeated lines can cause Algorithm::Diff::sdiff()
to take hours.) See also --timeout.
--docstring-as-code cloc considers docstrings to be comments, but this is
not always correct as docstrings represent regular
strings when they appear on the right hand side of an
assignment or as function arguments. This switch
forces docstrings to be counted as code.
--follow-links [Unix only] Follow symbolic links to directories
(sym links to files are always followed).
See also --stat.
--force-lang=<lang>[,<ext>]
Process all files that have a <ext> extension
with the counter for language <lang>. For
example, to count all .f files with the
Fortran 90 counter (which expects files to
end with .f90) instead of the default Fortran 77
counter, use
--force-lang="Fortran 90,f"
If <ext> is omitted, every file will be counted
with the <lang> counter. This option can be
specified multiple times (but that is only
useful when <ext> is given each time).
See also --script-lang, --lang-no-ext.
--force-lang-def=<file> Load language processing filters from <file>,
then use these filters instead of the built-in
filters. Note: languages which map to the same
file extension (for example:
MATLAB/Mathematica/Objective-C/MUMPS/Mercury;
Pascal/PHP; Lisp/OpenCL; Lisp/Julia; Perl/Prolog)
will be ignored as these require additional
processing that is not expressed in language
definition files. Use --read-lang-def to define
new language filters without replacing built-in
filters (see also --write-lang-def,
--write-lang-def-incl-dup).
--git Forces the inputs to be interpreted as git targets
(commit hashes, branch names, et cetera) if these
are not first identified as file or directory
names. This option overrides the --vcs=git logic
if this is given; in other words, --git gets its
list of files to work on directly from git using
the hash or branch name rather than from
'git ls-files'. This option can be used with
--diff to perform line count diffs between git
commits, or between a git commit and a file,
directory, or archive. Use -v/--verbose to see
the git system commands cloc issues.
--git-diff-rel Same as --git --diff, or just --diff if the inputs
are recognized as git targets. Only files which
have changed in either commit are compared.
--git-diff-all Git diff strategy #2: compare all files in the
repository between the two commits.
--ignore-whitespace Ignore horizontal white space when comparing files
with --diff. See also --ignore-case.
--ignore-case Ignore changes in case within file contents;
consider upper- and lowercase letters equivalent
when comparing files with --diff. See also
--ignore-whitespace.
--ignore-case-ext Ignore case of file name extensions. This will
cause problems counting some languages
(specifically, .c and .C are associated with C and
C++; this switch would count .C files as C rather
than C++ on *nix operating systems). File name
case insensitivity is always true on Windows.
--lang-no-ext=<lang> Count files without extensions using the <lang>
counter. This option overrides internal logic
for files without extensions (where such files
are checked against known scripting languages
by examining the first line for #!). See also
--force-lang, --script-lang.
--max-file-size=<MB> Skip files larger than <MB> megabytes when
traversing directories. By default, <MB>=100.
cloc's memory requirement is roughly twenty times
larger than the largest file so running with
files larger than 100 MB on a computer with less
than 2 GB of memory will cause problems.
Note: this check does not apply to files
explicitly passed as command line arguments.
--no-autogen[=list] Ignore files generated by code-production systems
such as GNU autoconf. To see a list of these files
(then exit), run with --no-autogen list
See also --autoconf.
--original-dir [Only effective in combination with
--strip-comments] Write the stripped files
to the same directory as the original files.
--read-binary-files Process binary files in addition to text files.
This is usually a bad idea and should only be
attempted with text files that have embedded
binary data.
--read-lang-def=<file> Load new language processing filters from <file>
and merge them with those already known to cloc.
If <file> defines a language cloc already knows
about, cloc's definition will take precedence.
Use --force-lang-def to over-ride cloc's
definitions (see also --write-lang-def,
--write-lang-def-incl-dup).
--script-lang=<lang>,<s> Process all files that invoke <s> as a #!
scripting language with the counter for language
<lang>. For example, files that begin with
#!/usr/local/bin/perl5.8.8
will be counted with the Perl counter by using
--script-lang=Perl,perl5.8.8
The language name is case insensitive but the
name of the script language executable, <s>,
must have the right case. This option can be
specified multiple times. See also --force-lang,
--lang-no-ext.
--sdir=<dir> Use <dir> as the scratch directory instead of
letting File::Temp chose the location. Files
written to this location are not removed at
the end of the run (as they are with File::Temp).
--skip-uniqueness Skip the file uniqueness check. This will give
a performance boost at the expense of counting
files with identical contents multiple times
(if such duplicates exist).
--stat Some file systems (AFS, CD-ROM, FAT, HPFS, SMB)
do not have directory 'nlink' counts that match
the number of its subdirectories. Consequently
cloc may undercount or completely skip the
contents of such file systems. This switch forces
File::Find to stat directories to obtain the
correct count. File search speed will decrease.
See also --follow-links.
--stdin-name=<file> Give a file name to use to determine the language
for standard input. (Use - as the input name to
receive source code via STDIN.)
--strip-comments=<ext> For each file processed, write to the current
directory a version of the file which has blank
and commented lines removed (in-line comments
persist). The name of each stripped file is the
original file name with .<ext> appended to it.
It is written to the current directory unless
--original-dir is on.
--strip-str-comments Replace comment markers embedded in strings with
'xx'. This attempts to work around a limitation
in Regexp::Common::Comment where comment markers
embedded in strings are seen as actual comment
markers and not strings, often resulting in a
'Complex regular subexpression recursion limit'
warning and incorrect counts. There are two
disadvantages to using this switch: 1/code count
performance drops, and 2/code generated with
--strip-comments will contain different strings
where ever embedded comments are found.
--sum-reports Input arguments are report files previously
created with the --report-file option in plain
format (eg. not JSON, YAML, XML, or SQL).
Makes a cumulative set of results containing the
sum of data from the individual report files.
--timeout <N> Ignore files which take more than <N> seconds
to process at any of the language's filter stages.
The default maximum number of seconds spent on a
filter stage is the number of lines in the file
divided by one thousand. Setting <N> to 0 allows
unlimited time. See also --diff-timeout.
--processes=NUM [Available only on systems with a recent version
of the Parallel::ForkManager module. Not
available on Windows.] Sets the maximum number of
cores that cloc uses. The default value of 0
disables multiprocessing.
--unix Override the operating system autodetection
logic and run in UNIX mode. See also
--windows, --show-os.
--use-sloccount If SLOCCount is installed, use its compiled
executables c_count, java_count, pascal_count,
php_count, and xml_count instead of cloc's
counters. SLOCCount's compiled counters are
substantially faster than cloc's and may give
a performance improvement when counting projects
with large files. However, these cloc-specific
features will not be available: --diff,
--count-and-diff, --strip-comments, --unicode.
--windows Override the operating system autodetection
logic and run in Microsoft Windows mode.
See also --unix, --show-os.
Filter Options
--include-content=<regex> Only count files containing text that matches the
given regular expression.
--exclude-content=<regex> Exclude files containing text that matches the given
regular expression.
--exclude-dir=<D1>[,D2,] Exclude the given comma separated directories
D1, D2, D3, et cetera, from being scanned. For
example --exclude-dir=.cache,test will skip
all files and subdirectories that have /.cache/
or /test/ as their parent directory.
Directories named .bzr, .cvs, .hg, .git, .svn,
and .snapshot are always excluded.
This option only works with individual directory
names so including file path separators is not
allowed. Use --fullpath and --not-match-d=<regex>
to supply a regex matching multiple subdirectories.
--exclude-ext=<ext1>[,<ext2>[...]]
Do not count files having the given file name
extensions.
--exclude-lang=<L1>[,L2[...]]
Exclude the given comma separated languages
L1, L2, L3, et cetera, from being counted.
--exclude-list-file=<file> Ignore files and/or directories whose names
appear in <file>. <file> should have one file
name per line. Only exact matches are ignored;
relative path names will be resolved starting from
the directory where cloc is invoked.
See also --list-file.
--fullpath Modifies the behavior of --match-f, --not-match-f,
and --not-match-d to include the file's path
in the regex, not just the file's basename.
(This does not expand each file to include its
absolute path, instead it uses as much of
the path as is passed in to cloc.)
Note: --match-d always looks at the full
path and therefore is unaffected by --fullpath.
--include-ext=<ext1>[,ext2[...]]
Count only languages having the given comma
separated file extensions. Use --show-ext to
see the recognized extensions.
--include-lang=<L1>[,L2[...]]
Count only the given comma separated languages
L1, L2, L3, et cetera. Use --show-lang to see
the list of recognized languages.
--match-d=<regex> Only count files in directories matching the Perl
regex. For example
--match-d='/(src|include)/'
only counts files in directories containing
/src/ or /include/. Unlike --not-match-d,
--match-f, and --not-match-f, --match-d always
compares the fully qualified path against the
regex.
--not-match-d=<regex> Count all files except those in directories
matching the Perl regex. Only the trailing
directory name is compared, for example, when
counting in /usr/local/lib, only 'lib' is
compared to the regex.
Add --fullpath to compare parent directories to
the regex.
Do not include file path separators at the
beginning or end of the regex.
--match-f=<regex> Only count files whose basenames match the Perl
regex. For example
--match-f='^[Ww]idget'
only counts files that start with Widget or widget.
Add --fullpath to include parent directories
in the regex instead of just the basename.
--not-match-f=<regex> Count all files except those whose basenames
match the Perl regex. Add --fullpath to include
parent directories in the regex instead of just
the basename.
--skip-archive=<regex> Ignore files that end with the given Perl regular
expression. For example, if given
--skip-archive='(zip|tar(.(gz|Z|bz2|xz|7z))?)'
the code will skip files that end with .zip,
.tar, .tar.gz, .tar.Z, .tar.bz2, .tar.xz, and
.tar.7z.
--skip-win-hidden On Windows, ignore hidden files.
Debug Options
--categorized=<file> Save file sizes in bytes, identified languages
and names of categorized files to <file>.
--counted=<file> Save names of processed source files to <file>.
--diff-alignment=<file> Write to <file> a list of files and file pairs
showing which files were added, removed, and/or
compared during a run with --diff. This switch
forces the --diff mode on.
--explain=<lang> Print the filters used to remove comments for
language <lang> and exit. In some cases the
filters refer to Perl subroutines rather than
regular expressions. An examination of the
source code may be needed for further explanation.
--help Print this usage information and exit.
--found=<file> Save names of every file found to <file>.
--ignored=<file> Save names of ignored files and the reason they
were ignored to <file>.
--print-filter-stages Print processed source code before and after
each filter is applied.
--show-ext[=<ext>] Print information about all known (or just the
given) file extensions and exit.
--show-lang[=<lang>] Print information about all known (or just the
given) languages and exit.
--show-os Print the value of the operating system mode
and exit. See also --unix, --windows.
-v[=<n>] Verbose switch (optional numeric value).
-verbose[=<n>] Long form of -v.
--version Print the version of this program and exit.
--write-lang-def=<file> Writes to <file> the language processing filters
then exits. Useful as a first step to creating
custom language definitions. Note: languages which
map to the same file extension will be excluded.
(See also --force-lang-def, --read-lang-def).
--write-lang-def-incl-dup=<file>
Same as --write-lang-def, but includes duplicated
extensions. This generates a problematic language
definition file because cloc will refuse to use
it until duplicates are removed.
Output Options
--3 Print third-generation language output.
(This option can cause report summation to fail
if some reports were produced with this option
while others were produced without it.)
--by-percent X Instead of comment and blank line counts, show
these values as percentages based on the value
of X in the denominator:
X = 'c' -> # lines of code
X = 'cm' -> # lines of code + comments
X = 'cb' -> # lines of code + blanks
X = 'cmb' -> # lines of code + comments + blanks
For example, if using method 'c' and your code
has twice as many lines of comments as lines
of code, the value in the comment column will
be 200%. The code column remains a line count.
--csv Write the results as comma separated values.
--csv-delimiter=<C> Use the character <C> as the delimiter for comma
separated files instead of ,. This switch forces --csv to be on.
--file-encoding=<E> Write output files using the <E> encoding instead of
the default ASCII (<E> = 'UTF-7'). Examples: 'UTF-16',
'euc-kr', 'iso-8859-16'. Known encodings can be
printed with
perl -MEncode -e 'print join("\n", Encode->encodings(":all")), "\n"'
--hide-rate Do not show line and file processing rates in the
output header. This makes output deterministic.
--json Write the results as JavaScript Object Notation
(JSON) formatted output.
--md Write the results as Markdown-formatted text.
--out=<file> Synonym for --report-file=<file>.
--progress-rate=<n> Show progress update after every <n> files are
processed (default <n>=100). Set <n> to 0 to
suppress progress output (useful when redirecting
output to STDOUT).
--quiet Suppress all information messages except for
the final report.
--report-file=<file> Write the results to <file> instead of STDOUT.
--sql=<file> Write results as SQL create and insert statements
which can be read by a database program such as
SQLite. If <file> is -, output is sent to STDOUT.
--sql-append Append SQL insert statements to the file specified
by --sql and do not generate table creation
statements. Only valid with the --sql option.
--sql-project=<name> Use <name> as the project identifier for the
current run. Only valid with the --sql option.
--sql-style=<style> Write SQL statements in the given style instead
of the default SQLite format. Styles include
'Oracle' and 'Named_Columns'.
--sum-one For plain text reports, show the SUM: output line
even if only one input file is processed.
--xml Write the results in XML.
--xsl=<file> Reference <file> as an XSL stylesheet within
the XML output. If <file> is 1 (numeric one),
writes a default stylesheet, cloc.xsl (or
cloc-diff.xsl if --diff is also given).
This switch forces --xml on.
--yaml Write the results in YAML.
[](1}}})
[]({{{1)
# [Recognized Languages ▲](#___top "click to go to top of document")
prompt> cloc --show-lang
ABAP (abap)
ActionScript (as)
Ada (ada, adb, ads, pad)
ADSO/IDSM (adso)
Agda (agda, lagda)
AMPLE (ample, dofile, startup)
AnsProlog (lp)
Ant (build.xml, build.xml)
ANTLR Grammar (g, g4)
Apex Class (cls)
Apex Trigger (trigger)
APL (apl, apla, aplc, aplf, apli, apln, aplo, dyalog, dyapp, mipage)
AppleScript (applescript)
Arduino Sketch (ino)
ArkTs (ets)
Arturo (art)
AsciiDoc (adoc, asciidoc)
ASP (asa, ashx, asp, axd)
ASP.NET (asax, ascx, asmx, aspx, master, sitemap, webinfo)
AspectJ (aj)
Assembly (a51, asm, nasm, S, s)
Astro (astro)
Asymptote (asy)
AutoHotkey (ahk, ahkl)
awk (auk, awk, gawk, mawk, nawk)
Bazel (BUILD)
BizTalk Orchestration (odx)
BizTalk Pipeline (btp)
Blade (blade, blade.php)
Bourne Again Shell (bash)
Bourne Shell (sh)
BrightScript (brs)
builder (xml.builder)
C (c, cats, ec, idc, pgc)
C Shell (csh, tcsh)
C# (cs)
C# Designer (designer.cs)
C++ (C, c++, c++m, cc, ccm, CPP, cpp, cppm, cxx, cxxm, h++, inl, ipp, ixx, pcc, tcc, tpp)
C/C++ Header (H, h, hh, hpp, hxx)
Cairo (cairo)
Cake Build Script (cake)
Carbon (carbon)
CCS (ccs)
Chapel (chpl)
Circom (circom)
Clean (dcl, icl)
Clojure (boot, cl2, clj, cljs.hl, cljscm, cljx, hic, riemann.config)
ClojureC (cljc)
ClojureScript (cljs)
CMake (cmake, cmake.in, CMakeLists.txt)
COBOL (CBL, cbl, ccp, COB, cob, cobol, cpy)
CoCoA 5 (c5, cocoa5, cocoa5server, cpkg5)
CoffeeScript (_coffee, cakefile, cjsx, coffee, iced)
ColdFusion (cfm, cfml)
ColdFusion CFScript (cfc)
Constraint Grammar (cg3, rlx)
Containerfile (Containerfile)
Coq (v)
Crystal (cr)
CSON (cson)
CSS (css)
CSV (csv)
Cucumber (feature)
CUDA (cu, cuh)
Cython (pxd, pxi, pyx)
D (d)
Dafny (dfy)
DAL (da)
Dart (dart)
Delphi Form (dfm)
DenizenScript (dsc)
Derw (derw)
dhall (dhall)
DIET (dt)
diff (diff, patch)
DITA (dita)
Dockerfile (Dockerfile, dockerfile)
DOORS Extension Language (dxl)
DOS Batch (BAT, bat, BTM, btm, CMD, cmd)
Drools (drl)
DTD (dtd)
dtrace (d)
ECPP (ecpp)
EEx (eex)
EJS (ejs)
Elixir (ex, exs)
Elm (elm)
Embedded Crystal (ecr)
ERB (ERB, erb)
Erlang (app.src, emakefile, erl, hrl, rebar.config, rebar.config.lock, rebar.lock, xrl, yrl)
Expect (exp)
F# (fsi, fs, fs)
F# Script (fsx)
Fennel (fnl)
Finite State Language (fsl, jssm)
Fish Shell (fish)
Flatbuffers (fbs)
Focus (focexec)
Forth (4th, e4, f83, fb, forth, fpm, fr, frt, ft, fth, rx, fs, f, for)
Fortran 77 (F, F77, f77, FOR, FTN, ftn, pfo, f, for)
Fortran 90 (F90, f90)
Fortran 95 (F95, f95)
Freemarker Template (ftl)
Futhark (fut)
FXML (fxml)
GDScript (gd)
Gencat NLS (msg)
Glade (glade, ui)
Gleam (gleam)
Glimmer JavaScript (gjs)
Glimmer TypeScript (gts)
GLSL (comp, fp, frag, frg, fsh, fshader, geo, geom, glsl, glslv, gshader, tesc, tese, vert, vrx, vsh, vshader)
Go (go, ʕ◔ϖ◔ʔ)
Godot Resource (tres)
Godot Scene (tscn)
Godot Shaders (gdshader)
Gradle (gradle, gradle.kts)
Grails (gsp)
GraphQL (gql, graphql, graphqls)
Groovy (gant, groovy, grt, gtpl, gvy, jenkinsfile)
Haml (haml, haml.deface)
Handlebars (handlebars, hbs)
Harbour (hb)
Hare (ha)
Haskell (hs, hsc, lhs)
Haxe (hx, hxsl)
HCL (hcl, nomad, tf, tfvars)
HLSL (cg, cginc, fxh, hlsl, hlsli, shader)
HolyC (HC)
Hoon (hoon)
HTML (htm, html, html.hl, xht)
HTML EEx (heex)
IDL (dlm, idl, pro)
Idris (idr)
Igor Pro (ipf)
Imba (imba)
INI (buildozer.spec, editorconfig, ini, lektorproject, prefs)
InstallShield (ism)
IPL (ipl)
Jai (jai)
Janet (janet)
Java (java)
JavaScript (_js, bones, cjs, es6, jake, jakefile, js, jsb, jscad, jsfl, jsm, jss, mjs, njs, pac, sjs, ssjs, xsjs, xsjslib)
JavaServer Faces (jsf)
JCL (jcl)
Jinja Template (j2, jinja, jinja2)
JSON (arcconfig, avsc, composer.lock, geojson, gltf, har, htmlhintrc, json, json-tmlanguage, jsonl, mcmeta, mcmod.info, tern-config, tern-project, tfstate, tfstate.backup, topojson, watchmanconfig, webapp, webmanifest, yyp)
JSON5 (json5)
JSP (jsp, jspf)
JSX (jsx)
Julia (jl)
Juniper Junos (junos)
Jupyter Notebook (ipynb)
Kermit (ksc)
Korn Shell (ksh)
Kotlin (kt, ktm, kts)
kvlang (kv)
Lean (hlean, lean)
Lem (lem)
LESS (less)
lex (l, lex)
LFE (lfe)
Linker Script (ld)
liquid (liquid)
Lisp (asd, el, lisp, lsp, cl, jl)
Literate Idris (lidr)
LiveLink OScript (oscript)
LLVM IR (ll)
Logos (x, xm)
Logtalk (lgt, logtalk)
Lua (lua, nse, p8, pd_lua, rbxs, wlua)
Luau (luau)
m4 (ac, m4)
make (am, Gnumakefile, gnumakefile, Makefile, makefile, mk)
Mako (mako, mao)
Markdown (contents.lr, markdown, md, mdown, mdwn, mdx, mkd, mkdn, mkdown, ronn, workbook)
Mathematica (cdf, ma, mathematica, mt, nbp, wl, wlt, m)
MATLAB (m)
Maven (pom, pom.xml)
Meson (meson.build)
Metal (metal)
Modelica (mo)
Modula3 (i3, ig, m3, mg)
Mojo (mojo, 🔥)
Mojom (mojom)
MoonBit (mbt, mbti, mbtx, mbty)
MSBuild script (btproj, csproj, msbuild, vcproj, wdproj, wixproj)
MUMPS (mps, m)
Mustache (mustache)
MXML (mxml)
NAnt script (build)
NASTRAN DMAP (dmap)
Nemerle (n)
NetLogo (nlogo, nls)
Nickel (ncl)
Nim (nim, nim.cfg, nimble, nimrod, nims)
Nix (nix)
Nunjucks (njk)
Objective-C (m)
Objective-C++ (mm)
OCaml (eliom, eliomi, ml, ml4, mli, mll, mly)
Odin (odin)
OpenCL (cl)
OpenSCAD (scad)
Oracle Forms (fmt)
Oracle PL/SQL (bod, fnc, prc, spc, trg)
Oracle Reports (rex)
P4 (p4)
Pascal (dpr, lpr, pas, pascal)
Pascal/Pawn (p)
Pascal/Puppet (pp)
Patran Command Language (pcl, ses)
Pawn (pawn, pwn)
PEG (peg)
peg.js (pegjs)
peggy (peggy)
Perl (ack, al, cpanfile, makefile.pl, perl, ph, plh, plx, pm, psgi, rexfile, pl, p6)
Pest (pest)
PHP (aw, ctp, phakefile, php, php3, php4, php5, php_cs, php_cs.dist, phps, phpt, phtml)
PHP/Pascal/Fortran/Pawn (inc)
Pig Latin (pig)
PL/I (pl1)
PL/M (lit, plm)
PlantUML (iuml, plantuml, pu, puml, wsd)
PO File (po)
Pony (pony)
PowerBuilder (pbt, sra, srf, srm, srs, sru, srw)
PowerShell (ps1, psd1, psm1)
Prisma Schema (prisma)
Processing (pde)
ProGuard (pro)
Prolog (P, prolog, yap, pl, p6, pro)
Properties (properties)
Protocol Buffers (proto)
PRQL (prql)
Pug (jade, pug)
PureScript (purs)
Python (buck, build.bazel, gclient, gyp, gypi, lmi, py, py3, pyde, pyi, pyp, pyt, pyw, sconscript, sconstruct, snakefile, tac, workspace, wscript, wsgi, xpy)
QML (qbs, qml)
Qt (ui)
Qt Linguist (ts)
Qt Project (pro)
R (expr-dist, R, r, rd, rprofile, rsx)
Racket (rkt, rktd, rktl, scrbl)
Raku (pm6, raku, rakumod)
Raku/Prolog (P6, p6)
RAML (raml)
RapydScript (pyj)
Razor (cshtml, razor)
ReasonML (re, rei)
ReScript (res, resi)
reStructuredText (rest, rest.txt, rst, rst.txt)
Rexx (pprx, rexx)
Ring (rform, rh, ring)
Rmd (Rmd)
RobotFramework (robot)
Ruby (appraisals, berksfile, brewfile, builder, buildfile, capfile, dangerfile, deliverfile, eye, fastfile, gemfile, gemfile.lock, gemspec, god, guardfile, irbrc, jarfile, jbuilder, mavenfile, mspec, podfile, podspec, pryrc, puppetfile, rabl, rake, rb, rbuild, rbw, rbx, ru, snapfile, thor, thorfile, vagrantfile, watchr)
Ruby HTML (rhtml)
Rust (rs, rs.in)
SaltStack (sls)
SAS (sas)
Sass (sass)
Scala (kojo, sbt, scala)
Scheme (sc, sch, scm, sld, sps, ss, sls)
SCSS (scss)
sed (sed)
SKILL (il)
SKILL++ (ils)
Slice (ice)
Slim (slim)
Slint (slint)
Smalltalk (st, cs)
Smarty (smarty, tpl)
Snakemake (rules, smk)
Softbridge Basic (SBL, sbl)
Solidity (sol)
SparForte (sp)
Specman e (e)
SQL (cql, mysql, psql, SQL, sql, tab, udf, viw)
SQL Data (data.sql)
SQL Stored Procedure (spc.sql, spoc.sql, sproc.sql, udf.sql)
Squirrel (nut)
Standard ML (fun, sig, sml)
Starlark (bazel, bzl)
Stata (ado, DO, do, doh, ihlp, mata, matah, sthlp)
Stylus (styl)
SugarSS (sss)
Svelte (svelte)
SVG (SVG, svg)
Swift (swift)
SWIG (i)
TableGen (td)
Tcl/Tk (itk, tcl, tk)
TEAL (teal)
Teamcenter met (met)
Teamcenter mth (mth)
Templ (templ)
TeX (aux, bbx, bib, bst, cbx, dtx, ins, lbx, ltx, mkii, mkiv, mkvi, sty, tex, cls)
Text (text, txt)
Thrift (thrift)
TITAN Project File Information (tpd)
Titanium Style Sheet (tss)
TLA+ (tla)
TNSDL (cii, cin, in1, in2, in3, in4, inf, interface, rou, sdl, sdt, spd, ssc, sst)
TOML (toml)
tspeg (jspeg, tspeg)
TTCN (ttcn, ttcn2, ttcn3, ttcnpp)
Twig (twig)
TypeScript (mts, tsx, ts)
Typst (typ)
Umka (um)
Unity-Prefab (mat, prefab)
Vala (vala)
Vala Header (vapi)
VB for Applications (VBA, vba)
Velocity Template Language (vm)
Verilog-SystemVerilog (sv, svh, v)
VHDL (VHD, vhd, VHDL, vhdl, vhf, vhi, vho, vhs, vht, vhw)
vim script (vim)
Visual Basic (BAS, bas, ctl, dsr, frm, FRX, frx, VBHTML, vbhtml, vbp, vbw, cls)
Visual Basic .NET (VB, vb, vbproj)
Visual Basic Script (VBS, vbs)
Visual Fox Pro (SCA, sca)
Visual Studio Solution (sln)
Visualforce Component (component)
Visualforce Page (page)
Vuejs Component (vue)
Vyper (vy)
Web Services Description (wsdl)
WebAssembly (wast, wat)
WGSL (wgsl)
Windows Message File (mc)
Windows Module Definition (def)
Windows Resource File (rc, rc2)
WiX include (wxi)
WiX source (wxs)
WiX string localization (wxl)
WXML (wxml)
WXSS (wxss)
X++ (xpo)
XAML (xaml)
xBase (prg, prw)
xBase Header (ch)
XHTML (xhtml)
XMI (XMI, xmi)
XML (adml, admx, ant, app.config, axml, builds, ccproj, ccxml, classpath, clixml, cproject, cscfg, csdef, csl, ct, depproj, ditamap, ditaval, dll.config, dotsettings, filters, fsproj, gmx, grxml, iml, ivy, jelly, jsproj, kml, launch, mdpolicy, mjml, natvis, ndproj, nproj, nuget.config, nuspec, odd, osm, packages.config, pkgproj, plist, proj, project, props, ps1xml, psc1, pt, rdf, resx, rss, scxml, settings.stylecop, sfproj, shproj, srdf, storyboard, sttheme, sublime-snippet, targets, tmcommand, tml, tmlanguage, tmpreferences, tmsnippet, tmtheme, urdf, ux, vcxproj, vsixmanifest, vssettings, vstemplate, vxml, web.config, web.debug.config, web.release.config, wsf, x3d, xacro, xib, xlf, xliff, XML, xml, xml.dist, xproj, xspec, xul, zcml)
XQuery (xq, xql, xqm, xquery, xqy)
XSD (XSD, xsd)
XSLT (XSL, xsl, XSLT, xslt)
Xtend (xtend)
yacc (y, yacc)
YAML (clang-format, clang-tidy, gemrc, glide.lock, mir, reek, rviz, sublime-syntax, syntax, yaml, yaml-tmlanguage, yml, yml.mysql)
Yang (yang)
Zig (zig)
zsh (zsh)
The above list can be customized by reading language definitions from a
file with the `--read-lang-def` or `--force-lang-def` options.
These file extensions map to multiple languages:
* `cj` files could be Clojure or Cangjie
* `cl` files could be Lisp or OpenCL
* `cls` files could be Visual Basic, TeX or Apex Class
* `cs` files could be C# or Smalltalk
* `d` files could be D or dtrace
* `f` files could be Fortran 77 or Forth
* `fnc` files could be Oracle PL or SQL
* `for` files could be Fortran 77 or Forth
* `fs` files could be F# or Forth
* `inc` files could be PHP or Pascal
* `itk` files could be Tcl or Tk
* `jl` files could be Lisp or Julia
* `lit` files could be PL or M
* `m` files could be MATLAB, Mathematica, Objective-C, MUMPS or Mercury
* `p6` files could be Perl or Prolog
* `pl` files could be Perl or Prolog
* `PL` files could be Perl or Prolog
* `pp` files could be Pascal or Puppet
* `pro` files could be IDL, Qt Project, Prolog or ProGuard
* `ts` files could be TypeScript or Qt Linguist
* `ui` files could be Qt or Glade
* `v` files could be Verilog-SystemVerilog or Coq
cloc has subroutines that attempt to identify the correct language based
on the file's contents for these special cases. Language identification
accuracy is a function of how much code the file contains; .m files with
just one or two lines for example, seldom have enough information to
correctly distinguish between MATLAB, Mercury, MUMPS, or Objective-C.
Languages with file extension collisions are difficult to customize with
`--read-lang-def` or `--force-lang-def` as they have no mechanism to
identify languages with common extensions. In this situation one must
modify the cloc source code.
[](1}}})
[]({{{1)
# [How It Works ▲](#___top "click to go to top of document")
cloc's method of operation resembles SLOCCount's: First, create a list
of files to consider. Next, attempt to determine whether or not found
files contain recognized computer language source code. Finally, for
files identified as source files, invoke language-specific routines to
count the number of source lines.
A more detailed description:
1. If the input file is an archive (such as a .tar.gz or .zip file),
create a temporary directory and expand the archive there using a
system call to an appropriate underlying utility (tar, bzip2, unzip,
etc) then add this temporary directory as one of the inputs. (This
works more reliably on Unix than on Windows.)
2. Use File::Find to recursively descend the input directories and make
a list of candidate file names. Ignore binary and zero-sized files.
3. Make sure the files in the candidate list have unique contents
(first by comparing file sizes, then, for similarly sized files,
compare MD5 hashes of the file contents with Digest::MD5). For each
set of identical files, remove all but the first copy, as determined
by a lexical sort, of identical files from the set. The removed
files are not included in the report. (The `--skip-uniqueness` switch
disables the uniqueness tests and forces all copies of files to be
included in the report.) See also the `--ignored=` switch to see which
files were ignored and why.
4. Scan the candidate file list for file extensions which cloc
associates with programming languages (see the `--show-lang` and
`--show-ext` options). Files which match are classified as
containing source
code for that language. Each file without an extension is opened
and its first line read to see if it is a Unix shell script
(anything that begins with #!). If it is shell script, the file is
classified by that scripting language (if the language is
recognized). If the file does not have a recognized extension or is
not a recognized scripting language, the file is ignored.
5. All remaining files in the candidate list should now be source files
for known programming languages. For each of these files:
1. Read the entire file into memory.
2. Count the number of lines (= Loriginal).
3. Remove blank lines, then count again (= Lnon_blank).
4. Loop over the comment filters defined for this language. (For
example, C++ has two filters: (1) remove lines that start with
optional whitespace followed by // and (2) remove text between
/* and */) Apply each filter to the code to remove comments.
Count the left over lines (= Lcode).
5. Save the counts for this language:
* blank lines = Loriginal - Lnon_blank
* comment lines = Lnon_blank - Lcode
* code lines = Lcode
The options modify the algorithm slightly. The `--read-lang-def` option
for example allows the user to read definitions of comment filters,
known file extensions, and known scripting languages from a file. The
code for this option is processed between Steps 2 and 3.
[](1}}})
[]({{{1)
# [Advanced Use ▲](#___top "click to go to top of document")
[](1}}})
[]({{{1)
## [Remove Comments from Source Code ▲](#___top "click to go to top of document")
How can you tell if cloc correctly identifies comments? One way to
convince yourself cloc is doing the right thing is to use its
`--strip-comments` option to remove comments and blank lines from files, then
compare the stripped-down files to originals.
Let's try this out with the SQLite amalgamation, a C file containing all
code needed to build the SQLite library along with a header file:
prompt> tar zxf sqlite-amalgamation-3.5.6.tar.gz
prompt> cd sqlite-3.5.6/
prompt> cloc --strip-comments=nc sqlite.c
1 text file.
1 unique file.
Wrote sqlite3.c.nc
0 files ignored.
http://cloc.sourceforge.net v 1.03 T=1.0 s (1.0 files/s, 82895.0 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code scale 3rd gen. equiv
-------------------------------------------------------------------------------
C 1 5167 26827 50901 x 0.77 = 39193.77
-------------------------------------------------------------------------------
The extension argument given to --strip-comments is arbitrary; here nc was used as an abbreviation for "no comments".
cloc removed over 31,000 lines from the file:
prompt> wc -l sqlite3.c sqlite3.c.nc
82895 sqlite3.c
50901 sqlite3.c.nc
133796 total
prompt> echo "82895 - 50901" | bc
31994
We can now compare the original file, sqlite3.c and the one stripped of
comments, sqlite3.c.nc with tools like diff or vimdiff and see what
exactly cloc considered comments and blank lines. A rigorous proof that
the stripped-down file contains the same C code as the original is to
compile these files and compare checksums of the resulting object files.
First, the original source file:
prompt> gcc -c sqlite3.c
prompt> md5sum sqlite3.o
cce5f1a2ea27c7e44b2e1047e2588b49 sqlite3.o
Next, the version without comments:
prompt> mv sqlite3.c.nc sqlite3.c
prompt> gcc -c sqlite3.c
prompt> md5sum sqlite3.o
cce5f1a2ea27c7e44b2e1047e2588b49 sqlite3.o
cloc removed over 31,000 lines of comments and blanks but did not modify the source code in any significant way since the resulting object file matches the original.
[](1}}})
[]({{{1)
## [Work with Compressed Archives ▲](#___top "click to go to top of document")
Versions of cloc before v1.07 required an
`--extract-with=CMD` option to tell cloc how
to expand an archive file. Beginning with v1.07 this is extraction is
attempted automatically. At the moment the automatic extraction method works
reasonably well on Unix-type OS's for the following file types:
`.tar.gz`,
`.tar.bz2`,
`.tar.xz`,
`.tgz`,
`.zip`,
`.ear`,
`.deb`.
Some of these extensions work on Windows if one has WinZip installed
in the default location (`C:\Program Files\WinZip\WinZip32.exe`).
Additionally, with newer versions of WinZip, the
[http://www.winzip.com/downcl.htm](command line add-on)
is needed for correct operation; in this case one would invoke cloc with
something like
--extract-with="\"c:\Program Files\WinZip\wzunzip\" -e -o >FILE< ."
Ref. http://sourceforge.net/projects/cloc/forums/forum/600963/topic/4021070?message=8938196
In situations where the automatic extraction fails, one can try the
`--extract-with=CMD`
option to count lines of code within tar files, Zip files, or
other compressed archives for which one has an extraction tool.
cloc takes the user-provided extraction command and expands the archive
to a temporary directory (created with File::Temp),
counts the lines of code in the temporary directory,
then removes that directory. While not especially helpful when dealing
with a single compressed archive (after all, if you're going to type
the extraction command anyway why not just manually expand the archive?)
this option is handy for working with several archives at once.
For example, say you have the following source tarballs on a Unix machine
perl-5.8.5.tar.gz
Python-2.4.2.tar.gz
and you want to count all the code within them. The command would be
cloc --extract-with='gzip -dc >FILE< | tar xf -' perl-5.8.5.tar.gz Python-2.4.2.tar.gz
If that Unix machine has GNU tar (which can uncompress and extract in
one step) the command can be shortened to
cloc --extract-with='tar zxf >FILE<' perl-5.8.5.tar.gz Python-2.4.2.tar.gz
On a Windows computer with WinZip installed in
`c:\Program Files\WinZip` the command would look like
cloc.exe --extract-with="\"c:\Program Files\WinZip\WinZip32.exe\" -e -o >FILE< ." perl-5.8.5.tar.gz Python-2.4.2.tar.gz
Java `.ear` files are Zip files that contain additional Zip
files. cloc can handle nested compressed archives without
difficulty--provided all such files are compressed and archived in the
same way. Examples of counting a
Java `.ear` file in Unix and Windows:
Unix> cloc --extract-with="unzip -d . >FILE< " Project.ear
DOS> cloc.exe --extract-with="\"c:\Program Files\WinZip\WinZip32.exe\" -e -o >FILE< ." Project.ear
[](1}}})
[]({{{1)
## [Differences ▲](#___top "click to go to top of document")
The `--diff` switch allows one to measure the relative change in
source code and comments between two versions of a file, directory,
or archive. Differences reveal much more than absolute code
counts of two file versions. For example, say a source file
has 100 lines and its developer delivers a newer version with
102 lines. Did the developer add two comment lines,
or delete seventeen source
lines and add fourteen source lines and five comment lines, or did
the developer
do a complete rewrite, discarding all 100 original lines and
adding 102 lines of all new source? The diff option tells how
many lines of source were added, removed, modified or stayed
the same, and how many lines of comments were added, removed,
modified or stayed the same.
Differences in blank lines are handled much more coarsely
because these are stripped by cloc early on. Unless a
file pair is identical, cloc will report only differences
in absolute counts of blank lines. In other words, one
can expect to see only entries for 'added' if the second
file has more blanks than the first, and 'removed' if the
situation is reversed. The entry for 'same' will be non-zero
only when the two files are identical.
In addition to file pairs, one can give cloc pairs of
directories, or pairs of file archives, or a file archive
and a directory. cloc will try to align
file pairs within the directories or archives and compare diffs
for each pair. For example, to see what changed between
GCC 4.4.0 and 4.5.0 one could do
cloc --diff gcc-4.4.0.tar.bz2 gcc-4.5.0.tar.bz2
Be prepared to wait a while for the results though; the `--diff`
option runs much more slowly than an absolute code count.
To see how cloc aligns files between the two archives, use the
`--diff-alignment` option
cloc --diff-alignment=align.txt gcc-4.4.0.tar.bz2 gcc-4.5.0.tar.bz2
to produce the file `align.txt` which shows the file pairs as well
as files added and deleted. The symbols `==` and `!=` before each
file pair indicate if the files are identical (`==`)
or if they have different content (`!=`).
Here's sample output showing the difference between the Python 2.6.6 and 2.7
releases:
prompt> cloc --diff Python-2.7.9.tgz Python-2.7.10.tar.xz
4315 text files.
4313 text files.s
2173 files ignored.
4 errors:
Diff error, exceeded timeout: /tmp/8ToGAnB9Y1/Python-2.7.9/Mac/Modules/qt/_Qtmodule.c
Diff error, exceeded timeout: /tmp/M6ldvsGaoq/Python-2.7.10/Mac/Modules/qt/_Qtmodule.c
Diff error (quoted comments?): /tmp/8ToGAnB9Y1/Python-2.7.9/Mac/Modules/qd/qdsupport.py
Diff error (quoted comments?): /tmp/M6ldvsGaoq/Python-2.7.10/Mac/Modules/qd/qdsupport.py
https://github.com/AlDanial/cloc v 1.65 T=298.59 s (0.0 files/s, 0.0 lines/s)
-----------------------------------------------------------------------------
Language files blank comment code
-----------------------------------------------------------------------------
Visual Basic
same 2 0 1 12
modified 0 0 0 0
added 0 0 0 0
removed 0 0 0 0
make
same 11 0 340 2952
modified 1 0 0 1
added 0 0 0 0
removed 0 0 0 0
diff
same 1 0 87 105
modified 0 0 0 0
added 0 0 0 0
removed 0 0 0 0
CSS
same 0 0 19 327
modified 1 0 0 1
added 0 0 0 0
removed 0 0 0 0
Objective-C
same 7 0 61 635
modified 0 0 0 0
added 0 0 0 0
removed 0 0 0 0
NAnt script
same 2 0 0 30
modified 0 0 0 0
added 0 0 0 0
removed 0 0 0 0
XML
same 3 0 2 72
modified 1 0 0 1
added 0 0 0 1
removed 0 1 0 0
Windows Resource File
same 3 0 56 206
modified 1 0 0 1
added 0 0 0 0
removed 0 0 0 0
Expect
same 6 0 161 565
modified 0 0 0 0
added 0 0 0 0
removed 0 0 0 0
HTML
same 14 0 11 2344
modified 0 0 0 0
added 0 0 0 0
removed 0 0 0 0
vim script
same 1 0 7 106
modified 0 0 0 0
added 0 0 0 0
removed 0 0 0 0
C++
same 2 0 18 128
modified 0 0 0 0
added 0 0 0 0
removed 0 0 0 0
Windows Module Definition
same 7 0 187 2080
modified 2 0 0 0
added 0 0 0 1
removed 0 1 0 2
Prolog
same 1 0 0 24
modified 0 0 0 0
added 0 0 0 0
removed 0 0 0 0
Javascript
same 3 0 49 229
modified 0 0 0 0
added 0 0 0 0
removed 0 0 0 0
Assembly
same 51 0 6794 12298
modified 0 0 0 0
added 0 0 0 0
removed 0 0 0 0
Bourne Shell
same 41 0 7698 45024
modified 1 0 0 3
added 0 13 2 64
removed 0 0 0 0
DOS Batch
same 29 0 107 494
modified 1 0 0 9
added 0 1 0 3
removed 0 0 0 0
MSBuild script
same 77 0 3 38910
modified 0 0 0 0
added 0 0 0 0
removed 0 0 0 0
Python
same 1947 0 109012 430335
modified 192 0 94 950
added 2 323 283 2532
removed 2 55 58 646
m4
same 18 0 191 15352
modified 1 0 0 2
added 1 31 0 205
removed 0 0 0 0
C
same 505 0 37439 347837
modified 45 0 13 218
added 0 90 33 795
removed 0 9 2 148
C/C++ Header
same 255 0 10361 66635
modified 5 0 5 7
added 0 1 3 300
removed 0 0 0 0
---------------------------------------------------------------------
SUM:
same 2986 0 172604 966700
modified 251 0 112 1193
added 3 459 321 3901
removed 2 66 60 796
---------------------------------------------------------------------
A pair of errors occurred.
The first pair was caused by timing out when computing diffs of the file
`Python-X/Mac/Modules/qt/_Qtmodule.c` in each Python version.
This file has > 26,000 lines of C code and takes more than
10 seconds--the default maximum duration for diff'ing a
single file--on my slow computer. (Note: this refers to
performing differences with
the `sdiff()` function in the Perl `Algorithm::Diff` module,
not the command line `diff` utility.) This error can be
overcome by raising the time to, say, 20 seconds
with `--diff-timeout 20`.
The second error is more problematic. The files
`Python-X/Mac/Modules/qd/qdsupport.py`
include Python docstring (text between pairs of triple quotes)
containing C comments. cloc treats docstrings as comments and handles them
by first converting them to C comments, then using the C comment removing
regular expression. Nested C comments yield erroneous results however.
[](1}}})
[]({{{1)
## [Create Custom Language Definitions ▲](#___top "click to go to top of document")
cloc can write its language comment definitions to a file or can read
comment definitions from a file, overriding the built-in definitions.
This can be useful when you want to use cloc to count lines of a
language not yet included, to change association of file extensions
to languages, or to modify the way existing languages are counted.
The easiest way to create a custom language definition file is to
make cloc write its definitions to a file, then modify that file:
Unix> cloc --write-lang-def=my_definitions.txt
creates the file `my_definitions.txt` which can be modifie