1cloc(1)                          User Commands                         cloc(1)
2
3
4

NAME

6       cloc - Count, or compute differences of, lines of source code and
7       comments.
8

SYNOPSIS

10         cloc [options] <FILE|DIR> ...
11

DESCRIPTION

13       Count, or compute differences of, physical lines of source code in the
14       given files (may be archives such as compressed tarballs or zip files)
15       and/or recursively below the given directories.  It is written entirely
16       in Perl, using only modules from the standard distribution.
17

OPTIONS

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

EXAMPLES

428       Count the lines of code in the Perl 5.10.0 compressed tar file on a
429       UNIX-like operating system:
430
431         cloc perl-5.10.0.tar.gz
432
433       Count the changes in files, code, and comments between Python releases
434       2.6.6 and 2.7:
435
436         cloc --diff Python-2.6.6.tar.bz  Python-2.7.tar.bz2
437
438       To see how cloc aligns files for comparison between two code bases, use
439       the --diff-alignment=FILE option.  Here the alignment information is
440       written to "align.txt":
441
442         cloc --diff-aligment=align.txt gcc-4.4.0.tar.bz2  gcc-4.5.0.tar.bz2
443
444       Print the recognized languages
445
446         cloc --show-lang
447
448       Remove comments from "foo.c" and save the result in "foo.c.nc"
449
450         cloc --strip-comments=nc foo.c
451
452       Additional examples can be found at <http://cloc.sourceforge.net>.
453

ENVIRONMENT

455       None.
456

FILES

458       None.
459

SEE ALSO

461       sloccount(1)
462

AUTHORS

464       The cloc program was written by Al Danial <al.danial@gmail.com> and is
465       Copyright (C) 2006-2017 <al.danial@gmail.com>.
466
467       The manual page was originally written by Jari Aalto
468       <jari.aalto@cante.net>.
469
470       Both the code and documentation is released under the GNU GPL version 2
471       or (at your option) any later version. For more information about
472       license, visit <http://www.gnu.org/copyleft/gpl.html>.
473
474
475
476cloc                              2019-01-31                           cloc(1)
Impressum