项目作者: AlDanial

项目描述 :
cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.
高级语言: Perl
项目地址: git://github.com/AlDanial/cloc.git
创建时间: 2015-09-07T03:30:43Z
项目社区:https://github.com/AlDanial/cloc

开源协议:GNU General Public License v2.0

下载


cloc

Count Lines of Code


cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.

Latest release: v2.04 (Jan. 31, 2025)

Version
Contributors
DOI
Forks
Downloads

cloc moved to GitHub in September 2015 after being hosted
at http://cloc.sourceforge.net/ since August 2006.

Warp packs green

Quick Start ▲

Step 1: Download cloc (several methods, see below) 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.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 has a
YouTube video
showing the steps in action.

a file

  1. prompt> cloc hello.c
  2. 1 text file.
  3. 1 unique file.
  4. 0 files ignored.
  5.  
  6. https://github.com/AlDanial/cloc v 1.65 T=0.04 s (28.3 files/s, 340.0 lines/s)
  7. -------------------------------------------------------------------------------
  8. Language files blank comment code
  9. -------------------------------------------------------------------------------
  10. C 1 0 7 5
  11. -------------------------------------------------------------------------------

a directory

  1. prompt> cloc gcc-5.2.0/gcc/c
  2. 16 text files.
  3. 15 unique files.
  4. 3 files ignored.
  5.  
  6. https://github.com/AlDanial/cloc v 1.65 T=0.23 s (57.1 files/s, 188914.0 lines/s)
  7. -------------------------------------------------------------------------------
  8. Language files blank comment code
  9. -------------------------------------------------------------------------------
  10. C 10 4680 6621 30812
  11. C/C++ Header 3 99 286 496
  12. -------------------------------------------------------------------------------
  13. SUM: 13 4779 6907 31308
  14. -------------------------------------------------------------------------------

an archive

We’ll pull cloc’s source zip file from GitHub, then count the contents:

  1. prompt> wget https://github.com/AlDanial/cloc/archive/master.zip
  2.  
  3. prompt> cloc master.zip
  4. https://github.com/AlDanial/cloc v 1.65 T=0.07 s (26.8 files/s, 141370.3 lines/s)
  5. -------------------------------------------------------------------------------
  6. Language files blank comment code
  7. -------------------------------------------------------------------------------
  8. Perl 2 725 1103 8713
  9. -------------------------------------------------------------------------------
  10. SUM: 2 725 1103 8713
  11. -------------------------------------------------------------------------------

a git repository, using a specific commit

This example uses code from
PuDB, a fantastic Python debugger.

  1. prompt> git clone https://github.com/inducer/pudb.git
  2.  
  3. prompt> cd pudb
  4.  
  5. prompt> cloc 6be804e07a5db
  6. 48 text files.
  7. 41 unique files.
  8. 8 files ignored.
  9.  
  10. github.com/AlDanial/cloc v 1.99 T=0.04 s (1054.9 files/s, 189646.8 lines/s)
  11. -------------------------------------------------------------------------------
  12. Language files blank comment code
  13. -------------------------------------------------------------------------------
  14. Python 28 1519 728 4659
  15. reStructuredText 6 102 20 203
  16. YAML 2 9 2 75
  17. Bourne Shell 3 6 0 17
  18. Text 1 0 0 11
  19. make 1 4 6 10
  20. -------------------------------------------------------------------------------
  21. SUM: 41 1640 756 4975
  22. -------------------------------------------------------------------------------

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):

  1. prompt> for d in ./*/ ; do (cd "$d" && echo "$d" && cloc --vcs git); done
  2. ./Project0/
  3. 7 text files.
  4. 7 unique files.
  5. 1 file ignored.
  6.  
  7. github.com/AlDanial/cloc v 1.71 T=0.02 s (390.2 files/s, 25687.6 lines/s)
  8. -------------------------------------------------------------------------------
  9. Language files blank comment code
  10. -------------------------------------------------------------------------------
  11. D 4 61 32 251
  12. Markdown 1 9 0 38
  13. make 1 0 0 4
  14. -------------------------------------------------------------------------------
  15. SUM: 6 70 32 293
  16. -------------------------------------------------------------------------------
  17. ./Project1/
  18. 7 text files.
  19. 7 unique files.
  20. 0 files ignored.
  21.  
  22. github.com/AlDanial/cloc v 1.71 T=0.02 s (293.0 files/s, 52107.1 lines/s)
  23. -------------------------------------------------------------------------------
  24. Language files blank comment code
  25. -------------------------------------------------------------------------------
  26. Go 7 165 282 798
  27. -------------------------------------------------------------------------------
  28. SUM: 7 165 282 798
  29. -------------------------------------------------------------------------------
  30. ./Project2/
  31. 49 text files.
  32. 47 unique files.
  33. 13 files ignored.
  34.  
  35. github.com/AlDanial/cloc v 1.71 T=0.10 s (399.5 files/s, 70409.4 lines/s)
  36. -------------------------------------------------------------------------------
  37. Language files blank comment code
  38. -------------------------------------------------------------------------------
  39. Python 33 1226 1026 3017
  40. C 4 327 337 888
  41. Markdown 1 11 0 28
  42. YAML 1 0 2 12
  43. -------------------------------------------------------------------------------
  44. SUM: 39 1564 1365 3945
  45. -------------------------------------------------------------------------------

each subdirectory of a particular directory (Windows/cmd.exe)

  1. for /D %I in (.\*) do cd %I && cloc --vcs git && cd ..


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.

Run via docker

These docker commands count lines of code in and below
the current directory:

  1. docker run --rm -v $PWD:/tmp aldanial/cloc .

Run via docker on git-bash

  1. 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):

  1. npm install -g cloc # https://www.npmjs.com/package/cloc
  2. sudo apt install cloc # Debian, Ubuntu
  3. sudo yum install cloc # Red Hat, Fedora
  4. sudo dnf install cloc # Fedora 22 or later
  5. sudo pacman -S cloc # Arch
  6. yay -S cloc-git # Arch AUR (latest git version)
  7. sudo emerge -av dev-util/cloc # Gentoo https://packages.gentoo.org/packages/dev-util/cloc
  8. sudo apk add cloc # Alpine Linux
  9. doas pkg_add cloc # OpenBSD
  10. sudo pkg install cloc # FreeBSD
  11. sudo port install cloc # macOS with MacPorts
  12. brew install cloc # macOS with Homebrew
  13. winget install AlDanial.Cloc # Windows with winget (might not work, ref https://github.com/AlDanial/cloc/issues/849)
  14. choco install cloc # Windows with Chocolatey
  15. 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.

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

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.

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

  1. » cd ~/Downloads
  2. » chmod +x cloc
  3. » ./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
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:

  1. cd C:\TEMP>
  2. C:TEMP\> perl cloc --version


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:

  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.

Other Counters ▲

If cloc does not suit your needs here are other freely available counters to consider:

Other references:

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:

  1. C:> cpan -i Digest::MD5
  2. C:> cpan -i Regexp::Common
  3. C:> cpan -i Algorithm::Diff
  4. C:> cpan -i PAR::Packer
  5. C:> cpan -i Win32::LongPath
  6. 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
5.30.2 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.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

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.


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:

  1. prompt> cloc perl-5.22.0.tar.gz
  2. 5605 text files.
  3. 5386 unique files.
  4. 2176 files ignored.
  5.  
  6. https://github.com/AlDanial/cloc v 1.65 T=25.49 s (134.7 files/s, 51980.3 lines/s)
  7. -----------------------------------------------------------------------------------
  8. Language files blank comment code
  9. -----------------------------------------------------------------------------------
  10. Perl 2892 136396 184362 536445
  11. C 130 24676 33684 155648
  12. C/C++ Header 148 9766 16569 147858
  13. Bourne Shell 112 4044 6796 42668
  14. Pascal 8 458 1603 8592
  15. XML 33 142 0 2410
  16. YAML 49 20 15 2078
  17. C++ 10 313 277 2033
  18. make 4 426 488 1986
  19. Prolog 12 438 2 1146
  20. JSON 14 1 0 1037
  21. yacc 1 85 76 998
  22. Windows Message File 1 102 11 489
  23. DOS Batch 14 92 41 389
  24. Windows Resource File 3 10 0 85
  25. D 1 5 7 8
  26. Lisp 2 0 3 4
  27. -----------------------------------------------------------------------------------
  28. SUM: 3434 176974 243934 903874
  29. -----------------------------------------------------------------------------------
  30.  

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.

Options ▲

  1. prompt> cloc --help
  2.  
  3. Usage: cloc [options] | |
  4. Count, or compute differences of, physical lines of source code in the
  5. given files (may be archives such as compressed tarballs or zip files,
  6. or git commit hashes or branch names) and/or recursively below the
  7. given directories.
  8. Input Options
  9. --extract-with= This option is only needed if cloc is unable
  10. to figure out how to extract the contents of
  11. the input file(s) by itself.
  12. Use to extract binary archive files (e.g.:
  13. .tar.gz, .zip, .Z). Use the literal '>FILE<' as
  14. a stand-in for the actual file(s) to be
  15. extracted. For example, to count lines of code
  16. in the input files
  17. gcc-4.2.tar.gz perl-5.8.8.tar.gz
  18. on Unix use
  19. --extract-with='gzip -dc >FILE< | tar xf -'
  20. or, if you have GNU tar,
  21. --extract-with='tar zxf >FILE<'
  22. and on Windows use, for example:
  23. --extract-with="\"c:\Program Files\WinZip\WinZip32.exe\" -e -o >FILE< ."
  24. (if WinZip is installed there).
  25. --list-file= Take the list of file and/or directory names to
  26. process from , which has one file/directory
  27. name per line. Only exact matches are counted;
  28. relative path names will be resolved starting from
  29. the directory where cloc is invoked. Set
  30. to - to read file names from a STDIN pipe.
  31. See also --exclude-list-file.
  32. --diff-list-file= Take the pairs of file names to be diff'ed from
  33. , whose format matches the output of
  34. --diff-alignment. (Run with that option to
  35. see a sample.) The language identifier at the
  36. end of each line is ignored. This enables --diff
  37. mode and bypasses file pair alignment logic.
  38. --vcs= Invoke a system call to to obtain a list of
  39. files to work on. If is 'git', then will
  40. invoke 'git ls-files' to get a file list and
  41. 'git submodule status' to get a list of submodules
  42. whose contents will be ignored. See also --git
  43. which accepts git commit hashes and branch names.
  44. If is 'svn' then will invoke 'svn list -R'.
  45. The primary benefit is that cloc will then skip
  46. files explicitly excluded by the versioning tool
  47. in question, ie, those in .gitignore or have the
  48. svn:ignore property.
  49. Alternatively may be any system command
  50. that generates a list of files.
  51. Note: cloc must be in a directory which can read
  52. the files as they are returned by . cloc will
  53. not download files from remote repositories.
  54. 'svn list -R' may refer to a remote repository
  55. to obtain file names (and therefore may require
  56. authentication to the remote repository), but
  57. the files themselves must be local.
  58. Setting to 'auto' selects between 'git'
  59. and 'svn' (or neither) depending on the presence
  60. of a .git or .svn subdirectory below the directory
  61. where cloc is invoked.
  62. --unicode Check binary files to see if they contain Unicode
  63. expanded ASCII text. This causes performance to
  64. drop noticeably.
  65. Processing Options
  66. --autoconf Count .in files (as processed by GNU autoconf) of
  67. recognized languages. See also --no-autogen.
  68. --by-file Report results for every source file encountered.
  69. --by-file-by-lang Report results for every source file encountered
  70. in addition to reporting by language.
  71. --config Read command line switches from instead of
  72. the default location of /home/al/.config/cloc/options.txt.
  73. The file should contain one switch, along with
  74. arguments (if any), per line. Blank lines and lines
  75. beginning with '#' are skipped. Options given on
  76. the command line take priority over entries read from
  77. the file.
  78. --count-and-diff
  79. First perform direct code counts of source file(s)
  80. of and separately, then perform a diff
  81. of these. Inputs may be pairs of files, directories,
  82. or archives. If --out or --report-file is given,
  83. three output files will be created, one for each
  84. of the two counts and one for the diff. See also
  85. --diff, --diff-alignment, --diff-timeout,
  86. --ignore-case, --ignore-whitespace.
  87. --diff Compute differences in code and comments between
  88. source file(s) of and . The inputs
  89. may be any mix of files, directories, archives,
  90. or git commit hashes. Use --diff-alignment to
  91. generate a list showing which file pairs where
  92. compared. When comparing git branches, only files
  93. which have changed in either commit are compared.
  94. See also --git, --count-and-diff, --diff-alignment,
  95. --diff-list-file, --diff-timeout, --ignore-case,
  96. --ignore-whitespace.
  97. --diff-timeout Ignore files which take more than seconds
  98. to process. Default is 10 seconds. Setting
  99. to 0 allows unlimited time. (Large files with many
  100. repeated lines can cause Algorithm::Diff::sdiff()
  101. to take hours.) See also --timeout.
  102. --docstring-as-code cloc considers docstrings to be comments, but this is
  103. not always correct as docstrings represent regular
  104. strings when they appear on the right hand side of an
  105. assignment or as function arguments. This switch
  106. forces docstrings to be counted as code.
  107. --follow-links [Unix only] Follow symbolic links to directories
  108. (sym links to files are always followed).
  109. See also --stat.
  110. --force-lang=[,]
  111. Process all files that have a extension
  112. with the counter for language . For
  113. example, to count all .f files with the
  114. Fortran 90 counter (which expects files to
  115. end with .f90) instead of the default Fortran 77
  116. counter, use
  117. --force-lang="Fortran 90,f"
  118. If is omitted, every file will be counted
  119. with the counter. This option can be
  120. specified multiple times (but that is only
  121. useful when is given each time).
  122. See also --script-lang, --lang-no-ext.
  123. --force-lang-def= Load language processing filters from ,
  124. then use these filters instead of the built-in
  125. filters. Note: languages which map to the same
  126. file extension (for example:
  127. MATLAB/Mathematica/Objective-C/MUMPS/Mercury;
  128. Pascal/PHP; Lisp/OpenCL; Lisp/Julia; Perl/Prolog)
  129. will be ignored as these require additional
  130. processing that is not expressed in language
  131. definition files. Use --read-lang-def to define
  132. new language filters without replacing built-in
  133. filters (see also --write-lang-def,
  134. --write-lang-def-incl-dup).
  135. --git Forces the inputs to be interpreted as git targets
  136. (commit hashes, branch names, et cetera) if these
  137. are not first identified as file or directory
  138. names. This option overrides the --vcs=git logic
  139. if this is given; in other words, --git gets its
  140. list of files to work on directly from git using
  141. the hash or branch name rather than from
  142. 'git ls-files'. This option can be used with
  143. --diff to perform line count diffs between git
  144. commits, or between a git commit and a file,
  145. directory, or archive. Use -v/--verbose to see
  146. the git system commands cloc issues.
  147. --git-diff-rel Same as --git --diff, or just --diff if the inputs
  148. are recognized as git targets. Only files which
  149. have changed in either commit are compared.
  150. --git-diff-all Git diff strategy #2: compare all files in the
  151. repository between the two commits.
  152. --ignore-whitespace Ignore horizontal white space when comparing files
  153. with --diff. See also --ignore-case.
  154. --ignore-case Ignore changes in case within file contents;
  155. consider upper- and lowercase letters equivalent
  156. when comparing files with --diff. See also
  157. --ignore-whitespace.
  158. --ignore-case-ext Ignore case of file name extensions. This will
  159. cause problems counting some languages
  160. (specifically, .c and .C are associated with C and
  161. C++; this switch would count .C files as C rather
  162. than C++ on *nix operating systems). File name
  163. case insensitivity is always true on Windows.
  164. --lang-no-ext= Count files without extensions using the
  165. counter. This option overrides internal logic
  166. for files without extensions (where such files
  167. are checked against known scripting languages
  168. by examining the first line for #!). See also
  169. --force-lang, --script-lang.
  170. --max-file-size= Skip files larger than megabytes when
  171. traversing directories. By default, =100.
  172. cloc's memory requirement is roughly twenty times
  173. larger than the largest file so running with
  174. files larger than 100 MB on a computer with less
  175. than 2 GB of memory will cause problems.
  176. Note: this check does not apply to files
  177. explicitly passed as command line arguments.
  178. --no-autogen[=list] Ignore files generated by code-production systems
  179. such as GNU autoconf. To see a list of these files
  180. (then exit), run with --no-autogen list
  181. See also --autoconf.
  182. --original-dir [Only effective in combination with
  183. --strip-comments] Write the stripped files
  184. to the same directory as the original files.
  185. --read-binary-files Process binary files in addition to text files.
  186. This is usually a bad idea and should only be
  187. attempted with text files that have embedded
  188. binary data.
  189. --read-lang-def= Load new language processing filters from
  190. and merge them with those already known to cloc.
  191. If defines a language cloc already knows
  192. about, cloc's definition will take precedence.
  193. Use --force-lang-def to over-ride cloc's
  194. definitions (see also --write-lang-def,
  195. --write-lang-def-incl-dup).
  196. --script-lang=, Process all files that invoke as a #!
  197. scripting language with the counter for language
  198. . For example, files that begin with
  199. #!/usr/local/bin/perl5.8.8
  200. will be counted with the Perl counter by using
  201. --script-lang=Perl,perl5.8.8
  202. The language name is case insensitive but the
  203. name of the script language executable, ,
  204. must have the right case. This option can be
  205. specified multiple times. See also --force-lang,
  206. --lang-no-ext.
  207. --sdir= Use as the scratch directory instead of
  208. letting File::Temp chose the location. Files
  209. written to this location are not removed at
  210. the end of the run (as they are with File::Temp).
  211. --skip-uniqueness Skip the file uniqueness check. This will give
  212. a performance boost at the expense of counting
  213. files with identical contents multiple times
  214. (if such duplicates exist).
  215. --stat Some file systems (AFS, CD-ROM, FAT, HPFS, SMB)
  216. do not have directory 'nlink' counts that match
  217. the number of its subdirectories. Consequently
  218. cloc may undercount or completely skip the
  219. contents of such file systems. This switch forces
  220. File::Find to stat directories to obtain the
  221. correct count. File search speed will decrease.
  222. See also --follow-links.
  223. --stdin-name= Give a file name to use to determine the language
  224. for standard input. (Use - as the input name to
  225. receive source code via STDIN.)
  226. --strip-comments= For each file processed, write to the current
  227. directory a version of the file which has blank
  228. and commented lines removed (in-line comments
  229. persist). The name of each stripped file is the
  230. original file name with . appended to it.
  231. It is written to the current directory unless
  232. --original-dir is on.
  233. --strip-str-comments Replace comment markers embedded in strings with
  234. 'xx'. This attempts to work around a limitation
  235. in Regexp::Common::Comment where comment markers
  236. embedded in strings are seen as actual comment
  237. markers and not strings, often resulting in a
  238. 'Complex regular subexpression recursion limit'
  239. warning and incorrect counts. There are two
  240. disadvantages to using this switch: 1/code count
  241. performance drops, and 2/code generated with
  242. --strip-comments will contain different strings
  243. where ever embedded comments are found.
  244. --sum-reports Input arguments are report files previously
  245. created with the --report-file option in plain
  246. format (eg. not JSON, YAML, XML, or SQL).
  247. Makes a cumulative set of results containing the
  248. sum of data from the individual report files.
  249. --timeout Ignore files which take more than seconds
  250. to process at any of the language's filter stages.
  251. The default maximum number of seconds spent on a
  252. filter stage is the number of lines in the file
  253. divided by one thousand. Setting to 0 allows
  254. unlimited time. See also --diff-timeout.
  255. --processes=NUM [Available only on systems with a recent version
  256. of the Parallel::ForkManager module. Not
  257. available on Windows.] Sets the maximum number of
  258. cores that cloc uses. The default value of 0
  259. disables multiprocessing.
  260. --unix Override the operating system autodetection
  261. logic and run in UNIX mode. See also
  262. --windows, --show-os.
  263. --use-sloccount If SLOCCount is installed, use its compiled
  264. executables c_count, java_count, pascal_count,
  265. php_count, and xml_count instead of cloc's
  266. counters. SLOCCount's compiled counters are
  267. substantially faster than cloc's and may give
  268. a performance improvement when counting projects
  269. with large files. However, these cloc-specific
  270. features will not be available: --diff,
  271. --count-and-diff, --strip-comments, --unicode.
  272. --windows Override the operating system autodetection
  273. logic and run in Microsoft Windows mode.
  274. See also --unix, --show-os.
  275. Filter Options
  276. --include-content= Only count files containing text that matches the
  277. given regular expression.
  278. --exclude-content= Exclude files containing text that matches the given
  279. regular expression.
  280. --exclude-dir=[,D2,] Exclude the given comma separated directories
  281. D1, D2, D3, et cetera, from being scanned. For
  282. example --exclude-dir=.cache,test will skip
  283. all files and subdirectories that have /.cache/
  284. or /test/ as their parent directory.
  285. Directories named .bzr, .cvs, .hg, .git, .svn,
  286. and .snapshot are always excluded.
  287. This option only works with individual directory
  288. names so including file path separators is not
  289. allowed. Use --fullpath and --not-match-d=
  290. to supply a regex matching multiple subdirectories.
  291. --exclude-ext=[,[...]]
  292. Do not count files having the given file name
  293. extensions.
  294. --exclude-lang=[,L2[...]]
  295. Exclude the given comma separated languages
  296. L1, L2, L3, et cetera, from being counted.
  297. --exclude-list-file= Ignore files and/or directories whose names
  298. appear in . should have one file
  299. name per line. Only exact matches are ignored;
  300. relative path names will be resolved starting from
  301. the directory where cloc is invoked.
  302. See also --list-file.
  303. --fullpath Modifies the behavior of --match-f, --not-match-f,
  304. and --not-match-d to include the file's path
  305. in the regex, not just the file's basename.
  306. (This does not expand each file to include its
  307. absolute path, instead it uses as much of
  308. the path as is passed in to cloc.)
  309. Note: --match-d always looks at the full
  310. path and therefore is unaffected by --fullpath.
  311. --include-ext=[,ext2[...]]
  312. Count only languages having the given comma
  313. separated file extensions. Use --show-ext to
  314. see the recognized extensions.
  315. --include-lang=[,L2[...]]
  316. Count only the given comma separated languages
  317. L1, L2, L3, et cetera. Use --show-lang to see
  318. the list of recognized languages.
  319. --match-d= Only count files in directories matching the Perl
  320. regex. For example
  321. --match-d='/(src|include)/'
  322. only counts files in directories containing
  323. /src/ or /include/. Unlike --not-match-d,
  324. --match-f, and --not-match-f, --match-d always
  325. compares the fully qualified path against the
  326. regex.
  327. --not-match-d= Count all files except those in directories
  328. matching the Perl regex. Only the trailing
  329. directory name is compared, for example, when
  330. counting in /usr/local/lib, only 'lib' is
  331. compared to the regex.
  332. Add --fullpath to compare parent directories to
  333. the regex.
  334. Do not include file path separators at the
  335. beginning or end of the regex.
  336. --match-f= Only count files whose basenames match the Perl
  337. regex. For example
  338. --match-f='^[Ww]idget'
  339. only counts files that start with Widget or widget.
  340. Add --fullpath to include parent directories
  341. in the regex instead of just the basename.
  342. --not-match-f= Count all files except those whose basenames
  343. match the Perl regex. Add --fullpath to include
  344. parent directories in the regex instead of just
  345. the basename.
  346. --skip-archive= Ignore files that end with the given Perl regular
  347. expression. For example, if given
  348. --skip-archive='(zip|tar(.(gz|Z|bz2|xz|7z))?)'
  349. the code will skip files that end with .zip,
  350. .tar, .tar.gz, .tar.Z, .tar.bz2, .tar.xz, and
  351. .tar.7z.
  352. --skip-win-hidden On Windows, ignore hidden files.
  353. Debug Options
  354. --categorized= Save file sizes in bytes, identified languages
  355. and names of categorized files to .
  356. --counted= Save names of processed source files to .
  357. --diff-alignment= Write to a list of files and file pairs
  358. showing which files were added, removed, and/or
  359. compared during a run with --diff. This switch
  360. forces the --diff mode on.
  361. --explain= Print the filters used to remove comments for
  362. language and exit. In some cases the
  363. filters refer to Perl subroutines rather than
  364. regular expressions. An examination of the
  365. source code may be needed for further explanation.
  366. --help Print this usage information and exit.
  367. --found= Save names of every file found to .
  368. --ignored= Save names of ignored files and the reason they
  369. were ignored to .
  370. --print-filter-stages Print processed source code before and after
  371. each filter is applied.
  372. --show-ext[=] Print information about all known (or just the
  373. given) file extensions and exit.
  374. --show-lang[=] Print information about all known (or just the
  375. given) languages and exit.
  376. --show-os Print the value of the operating system mode
  377. and exit. See also --unix, --windows.
  378. -v[=] Verbose switch (optional numeric value).
  379. -verbose[=] Long form of -v.
  380. --version Print the version of this program and exit.
  381. --write-lang-def= Writes to the language processing filters
  382. then exits. Useful as a first step to creating
  383. custom language definitions. Note: languages which
  384. map to the same file extension will be excluded.
  385. (See also --force-lang-def, --read-lang-def).
  386. --write-lang-def-incl-dup=
  387. Same as --write-lang-def, but includes duplicated
  388. extensions. This generates a problematic language
  389. definition file because cloc will refuse to use
  390. it until duplicates are removed.
  391. Output Options
  392. --3 Print third-generation language output.
  393. (This option can cause report summation to fail
  394. if some reports were produced with this option
  395. while others were produced without it.)
  396. --by-percent X Instead of comment and blank line counts, show
  397. these values as percentages based on the value
  398. of X in the denominator:
  399. X = 'c' -> # lines of code
  400. X = 'cm' -> # lines of code + comments
  401. X = 'cb' -> # lines of code + blanks
  402. X = 'cmb' -> # lines of code + comments + blanks
  403. For example, if using method 'c' and your code
  404. has twice as many lines of comments as lines
  405. of code, the value in the comment column will
  406. be 200%. The code column remains a line count.
  407. --csv Write the results as comma separated values.
  408. --csv-delimiter= Use the character as the delimiter for comma
  409. separated files instead of ,. This switch forces --csv to be on.
  410. --file-encoding= Write output files using the encoding instead of
  411. the default ASCII ( = 'UTF-7'). Examples: 'UTF-16',
  412. 'euc-kr', 'iso-8859-16'. Known encodings can be
  413. printed with
  414. perl -MEncode -e 'print join("\n", Encode->encodings(":all")), "\n"'
  415. --hide-rate Do not show line and file processing rates in the
  416. output header. This makes output deterministic.
  417. --json Write the results as JavaScript Object Notation
  418. (JSON) formatted output.
  419. --md Write the results as Markdown-formatted text.
  420. --out= Synonym for --report-file=.
  421. --progress-rate= Show progress update after every files are
  422. processed (default =100). Set to 0 to
  423. suppress progress output (useful when redirecting
  424. output to STDOUT).
  425. --quiet Suppress all information messages except for
  426. the final report.
  427. --report-file= Write the results to instead of STDOUT.
  428. --sql= Write results as SQL create and insert statements
  429. which can be read by a database program such as
  430. SQLite. If is -, output is sent to STDOUT.
  431. --sql-append Append SQL insert statements to the file specified
  432. by --sql and do not generate table creation
  433. statements. Only valid with the --sql option.
  434. --sql-project= Use as the project identifier for the
  435. current run. Only valid with the --sql option.
  436. --sql-style=