Count Lines of Code
cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.
Latest release: v2.10 (July 4, 2026)
cloc moved to GitHub in September 2015 after being hosted at http://cloc.sourceforge.net/ since August 2006.
Quick Start
Step 1: Install cloc (see Install from Github Releases and Install via package manager) or run cloc's docker image. 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.10.pl) or a Windows executable
(cloc-2.10.exe).
On this page, cloc is the generic term
used to refer to any of these.
Include Security has a YouTube video 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 ..
Sponsors
Atlas Cloud is a full-modal AI inference platform that gives developers a single AI API to access video generation, image generation, and LLM APIs. Instead of managing multiple vendor integrations, you connect once and get unified access to 300+ curated models across all modalities.
Overview
cloc counts blank lines, comment lines, and physical lines of source code in many programming 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) 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 5.6.1 or higher, Strawberry Perl, Windows Subsystem for Linux, Cygwin, MobaXTerm with the Perl plug-in installed, or a mingw environment and terminal such as provided by Git for Windows. Alternatively one can use the Windows binary of cloc generated with PAR::Packer 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, Damian Conway and Abigail's Perl module Regexp::Common, Sean M. Burke's Perl module Win32::Autoglob, and Tye McQueen's Perl module Algorithm::Diff. Language scale factors were derived from Mayes Consulting, LLC web site http://softwareestimator.com/IndustryData2.htm.
New releases nominally appear every six months.
Install from Github Releases
Grab the latest release of cloc from the Releases section of this repository.
Source version on Linux/macOS
Save the latest source file, for example cloc-2.10.pl,
as cloc (if you prefer the shorter command name) somewhere on your PATH.
After downloading, make the file executable:
cd ~/Downloads mv cloc-2.10.pl cloc chmod a+rx cloc ./cloc --version # make sure it runs mv cloc ~/bin # for example, if ~/bin is in $PATH
Source version on Windows
You'll need a Perl interpreter such as Strawberry Perl
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:
cd C:\TEMP>
C:TEMP\> perl cloc-2.10.pl --version
Binary version on Windows
Download the latest released Windows executable, for example cloc-2.10.exe
and save it as cloc.exe (if desired) in a directory on your PATH.
There is no binary version for Linux or macOS.
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.
Run via docker
These docker commands count lines of code in and below the current directory:
docker run --rm -v $PWD:/tmp aldanial/cloc .
Run via docker on git-bash
docker run --rm -v "/$(pwd -W)":/tmp aldanial/cloc .
Development version
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.
License
cloc is licensed under the GNU General Public License, v 2, 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.
Why Use cloc?
cloc has many features that make it easy to use, thorough, extensible, and portable:
- Exists as a single, self-contained file that requires minimal installation effort---just download the file and run it.
- Can read language comment definitions from a file and thus potentially work with computer languages that do not yet exist.
- Allows results from multiple runs to be summed together by language and by project.
- Can produce results in a variety of formats: plain text, Markdown, SQL, JSON, XML, YAML, comma separated values.
- Can count code within compressed archives (tar balls, Zip files, Java .ear files).
- Has numerous troubleshooting options.
- Handles file and directory names with spaces and other unusual characters.
- Has no dependencies outside the standard Perl distribution.
- 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.
Other Counters
If cloc does not suit your needs here are other freely available counters to consider:
Other references:
- QSM's directory of code counting tools.
- The Wikipedia entry for source code line counts.
Regexp::Common, Digest::MD5, Win32::Autoglob, Algorithm::Diff
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.
Building a Windows Executable
Create your own executable
The most robust option for creating a Windows executable of
cloc is to use ActiveState's Perl Development Kit.
It includes a utility, perlapp, which can build stand-alone
Windows, Mac, and Linux binaries of Perl source code.
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.10.exe cloc-2.10.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.10.exe,
was built on a 64 bit Windows 11 computer using
Strawberry Perl
5.32.1 and
PAR::Packer
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.10.exe: https://www.virustotal.com/gui/file/97786c4b5bb71d2be67e42061a2f5d03db73bbf88228f8710001d770e867bbef/detection
cloc-2.08.exe: https://www.virustotal.com/gui/file/4529557d957ade0dd45746eae10e9c51ee01061bb617eeeab256672faf6e42c6?nocache=1
cloc-2.06.exe: https://www.virustotal.com/gui/file/bbe48de9102d0f2520d292d65897001c1d068340eb7cd74dd1ee30c1a9091c4a?nocache=1
cloc-2.04.exe: https://www.virustotal.com/gui/file/89cda0038bf4e13c6c13ebc1e60bec4dfad362e69ac8a5b8e2d5ebe3020359e1
cloc-2.02-winget.exe: (includes PR 850 to allow running from a symlink on Windows) 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
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.
Basic Use
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.
GUI Frontends
Several GUI frontends to cloc are available:
- cloctui
- ClocViewer
- codeflower
- cloc-studio (for macOS)
Options
Full options list (cloc --help) (click the triangle to see all option)