1cloc(1) User Commands cloc(1)
2
3
4
6 cloc - Count, or compute differences of, lines of source code and
7 comments.
8
10 cloc [options] <FILE|DIR> ...
11
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 or git commit hashes or branch names) and/or recursively below the
16 given directories. It is written entirely in Perl, using only modules
17 from the standard distribution.
18
20 Input Options
21 To count standard input, use the special filename - and either
22 --stdin-name=FILE to tell cloc the name of the file being piped in, or
23 --force-lang=LANG to apply the LANG counter to all input.
24
25 --extract-with=CMD
26 This option is only needed if cloc is unable to figure out how to
27 extract the contents of the input file(s) by itself. Use CMD to
28 extract binary archive files (e.g.: .tar.gz, .zip, .Z). Use the
29 literal '>FILE<' as a stand-in for the actual file(s) to be
30 extracted. For example, to count lines of code in the input files
31 gcc-4.2.tar.gz perl-5.8.8.tar.gz on Unix use:
32
33 --extract-with='gzip -dc >FILE< | tar xf -
34
35 or, if you have GNU tar:
36
37 --extract-with='tar zxf >FILE<'
38
39 and on Windows, use, for example:
40
41 --extract-with="\"c:\Program Files\WinZip\WinZip32.exe\" -e -o >FILE<
42
43 --list-file=FILE
44 Take the list of file and/or directory names to process from FILE,
45 which has one file/directory name per line. Only exact matches are
46 counted; relative path names will be resolved starting from the
47 directory where cloc is invoked. Set FILE to - to read file names
48 from a STDIN pipe. See also --exclude-list-file.
49
50 --diff-list-file=FILE
51 Take the pairs of file names to be diff'ed from FILE, whose format
52 matches the output of --diff-alignment. (Run with that option to
53 see a sample.) The language identifier at the end of each line is
54 ignored. This enables --diff mode and by-passes file pair
55 alignment logic.
56
57 --vcs=VCS
58 Invoke a system call to VCS to obtain a list of files to work on.
59 If VCS is 'git', then will invoke 'git ls-files' to get a file list
60 and 'git submodule status' to get a list of submodules whose
61 contents will be ignored. See also --git which accepts git commit
62 hashes and branch names. If VCS is 'svn' then will invoke 'svn
63 list -R'. The primary benefit is that cloc will then skip files
64 explicitly excluded by the versioning tool in question, ie, those
65 in .gitignore or have the svn:ignore property. Alternatively VCS
66 may be any system command that generates a list of files. Note:
67 cloc must be in a directory which can read the files as they are
68 returned by VCS. cloc will not download files from remote
69 repositories. 'svn list -R' may refer to a remote repository to
70 obtain file names (and therefore may require authentication to the
71 remote repository), but the files themselves must be local.
72 Setting VCS to 'auto' selects between 'git' and 'svn' (or neither)
73 depending on the presence of a .git or .svn subdirectory below the
74 directory where cloc is invoked.
75
76 --unicode
77 Check binary files to see if they contain Unicode expanded ASCII
78 text. This causes performance to drop noticeably.
79
80 Processing Options
81 --autoconf
82 Count .in files (as processed by GNU autoconf) of recognized
83 languages. See also --no-autogen.
84
85 --by-file
86 Report results for every source file encountered.
87
88 --by-file-by-lang
89 Report results for every source file encountered in addition to
90 reporting by language.
91
92 --config FILE
93 First perform direct code counts of source file(s)
94
95 Read command line switches from FILE instead of the default
96 location of ~/.config/cloc/options.txt. The file should contain
97 one switch, along with arguments (if any), per line. Blank lines
98 and lines beginning with '#' are skipped. Options given on the
99 command line take priority over entries read from the file.
100
101 --count-and-diff SET1 SET2
102 First perform direct code counts of source file(s) of SET1 and SET2
103 separately, then perform a diff of these. Inputs may be pairs of
104 files, directories, or archives. If --out or --report-file is
105 given, three output files will be created, one for each of the two
106 counts and one for the diff. See also --diff, --diff-alignment,
107 --diff-timeout, --ignore-case, --ignore-whitespace.
108
109 --diff SET1 SET2
110 Compute differences in code and comments between source file(s) of
111 SET1 and SET2. The inputs may be pairs of files, directories, or
112 archives. Use --diff-alignment to generate a list showing which
113 file pairs where compared. See also --count-and-diff,
114 --diff-alignment, --diff-timeout, --ignore-case,
115 --ignore-whitespace.
116
117 --diff-timeout N
118 Ignore files which take more than N seconds to process. Default is
119 10 seconds. Setting N to 0 allows unlimited time. (Large files
120 with many repeated lines can cause Algorithm::Diff::sdiff() to take
121 hours.)
122
123 --docstring-as-code
124 cloc considers docstrings to be comments, but this is not always
125 correct as docstrings represent regular strings when they appear on
126 the right hand side of an assignment or as function arguments.
127 This switch forces docstrings to be counted as code.
128
129 --follow-links
130 [Unix only] Follow symbolic links to directories (sym links to
131 files are always followed).
132
133 --force-lang=LANG[,EXT]
134 Process all files that have a EXT extension with the counter for
135 language LANG. For example, to count all .f files with the Fortran
136 90 counter (which expects files to end with .f90) instead of the
137 default Fortran 77 counter, use:
138
139 --force-lang="Fortran 90",f
140
141 If EXT is omitted, every file will be counted with the LANG
142 counter. This option can be specified multiple times (but that is
143 only useful when EXT is given each time). See also --script-lang,
144 --lang-no-ext.
145
146 --force-lang-def=FILE
147 Load language processing filters from FILE, then use these filters
148 instead of the built-in filters. Note: languages which map to the
149 same file extension (for example: MATLAB/Objective-C/MUMPS;
150 Pascal/PHP; Lisp/OpenCL; Lisp/Julia; Perl/Prolog) will be ignored
151 as these require additional processing that is not expressed in
152 language definition files. Use --read-lang-def to define new
153 language filters without replacing built-in filters (see also
154 --write-lang-def, --write-lang-def-incl-dup).
155
156 --git
157 Forces the inputs to be interpreted as git targets (commit hashes,
158 branch names, et cetera) if these are not first identified as file
159 or directory names. This option overrides the --vcs=git logic if
160 this is given; in other words, --git gets its list of files to work
161 on directly from git using the hash or branch name rather than from
162 'git ls-files'. This option can be used with --diff to perform
163 line count diffs between git commits, or between a git commit and a
164 file, directory, or archive. Use -v/--verbose to see the git
165 system commands cloc issues.
166
167 --ignore-whitespace
168 Ignore horizontal white space when comparing files with --diff.
169 See also --ignore-case.
170
171 --ignore-case
172 Ignore changes in case within file contents; consider upper- and
173 lowercase letters equivalent when comparing files with --diff. See
174 also --ignore-whitespace.
175
176 --git-diff-rel
177 Same as --git --diff, or just --diff if the inputs are recognized
178 as git targets. Only files which have changed in either commit are
179 compared.
180
181 --git-diff-all
182 Git diff strategy #2: compare all files in the repository between
183 the two commits.
184
185 --ignore-case-ext
186 Ignore case of file name extensions. This will cause problems
187 counting some languages (specifically, .c and .C are associated
188 with C and C++; this switch would count .C files as C rather than
189 C++ on *nix operating systems). File name case insensitivity is
190 always true on Windows.
191
192 --lang-no-ext=LANG
193 Count files without extensions using the LANG counter. This option
194 overrides internal logic for files without extensions (where such
195 files are checked against known scripting languages by examining
196 the first line for "#!"). See also --force-lang, --script-lang.
197
198 --max-file-size=MB
199 Skip files larger than "MB" megabytes when traversing directories.
200 By default, "MB"=100. cloc's memory requirement is roughly twenty
201 times larger than the largest file so running with files larger
202 than 100 MB on a computer with less than 2 GB of memory will cause
203 problems. Note: this check does not apply to files explicitly
204 passed as command line arguments.
205
206 --no-autogen[=list]
207 Ignore files generated by code-production systems such as GNU
208 autoconf. To see a list of these files (then exit), run with
209 --no-autogen list See also --autoconf.
210
211 ==item b<--original-dir>
212
213 Only effective in combination with --strip-comments. Write the
214 stripped files to the same directory as the original files.
215
216 --read-binary-files
217 Process binary files in addition to text files. This is usually a
218 bad idea and should only be attempted with text files that have
219 embedded binary data.
220
221 --read-lang-def=FILE
222 Load new language processing filters from FILE and merge them with
223 those already known to cloc. If FILE defines a language cloc
224 already knows about, cloc's definition will take precedence. Use
225 --force-lang-def to over-ride cloc's definitions. (see also
226 --write-lang-def).
227
228 --script-lang=LANG,S
229 Process all files that invoke "S" as a "#!" scripting language with
230 the counter for language LANG. For example, files that begin with
231 "#!/usr/local/bin/perl5.8.8" will be counted with the Perl counter
232 by using
233
234 --script-lang=Perl,perl5.8.8
235
236 The language name is case insensitive but the name of the script
237 language executable, "S", must have the right case. This option can
238 be specified multiple times. See also --force-lang.
239
240 --sdir=DIR
241 Use DIR as the scratch directory instead of letting File::Temp
242 chose the location. Files written to this location are not removed
243 at the end of the run (as they are with File::Temp).
244
245 --skip-uniqueness
246 Skip the file uniqueness check. This will give a performance boost
247 at the expense of counting files with identical contents multiple
248 times (if such duplicates exist).
249
250 --stat
251 Some file systems (AFS, CD-ROM, FAT, HPFS, SMB) do not have
252 directory 'nlink' counts that match the number of its
253 subdirectories. Consequently cloc may undercount or completely
254 skip the contents of such file systems. This switch forces
255 File::Find to stat directories to obtain the correct count. File
256 search spead will decrease. See also --follow-links.
257
258 --stdin-name=FILE
259 Count lines streamed via STDIN as if they came from a file named
260 FILE.
261
262 --strip-comments=EXT
263 For each file processed, write to the current directory a version
264 of the file which has blank and commented lines removed (in-line
265 comments persist). The name of each stripped file is the original
266 file name with ".EXT" appended to it. It is written to the current
267 directory unless --original-dir is on.
268
269 --original-dir
270 Write the stripped files the same directory as the original files.
271 Only effective in combination with --strip-comments.
272
273 --strip-str-comments
274 Replace comment markers embedded in strings with 'xx'. This
275 attempts to work around a limitation in Regexp::Common::Comment
276 where comment markers embedded in strings are seen as actual
277 comment markers and not strings, often resulting in a 'Complex
278 regular subexpression recursion limit' warning and incorrect
279 counts. There are two disadvantages to using this switch: 1/code
280 count performance drops, and 2/code generated with --strip-comments
281 will contain different strings where ever embedded comments are
282 found.
283
284 --sum-reports
285 Input arguments are report files previously created with the
286 --report-file option. Makes a cumulative set of results containing
287 the sum of data from the individual report files.
288
289 --timeout=N
290
291 Ignore files which take more than <N> seconds to process at any of
292 the language's filter stages. The default maximum number of
293 seconds spent on a filter stage is the number of lines in the file
294 divided by one thousand. Setting N to 0 allows unlimited time.
295 See also --diff-timeout.
296
297 --processes=NUM
298 [Available only on systems with a recent version of the
299 Parallel::ForkManager module. Not available on Windows.] Sets the
300 maximum number of cores that cloc uses. The default value of 0
301 disables multiprocessing.
302
303 --unix
304 Over-ride the operating system detection logic and run in UNIX
305 mode. See also --windows, --show-os.
306
307 --use-sloccount
308 If SLOCCount is installed, use its compiled executables c_count,
309 java_count, pascal_count, php_count, and xml_count instead of
310 cloc's counters. SLOCCount's compiled counters are substantially
311 faster than cloc's and may give a performance improvement when
312 counting projects with large files. However, these cloc-specific
313 features will not be available: --diff, --count-and-diff,
314 --strip-comments, --unicode.
315
316 --windows
317 Over-ride the operating system detection logic and run in Microsoft
318 Windows mode. See also --unix, --show-os.
319
320 Filter Options
321 --exclude-content=REGEX
322 Exclude files containing text that matches the given regular
323 expression.
324
325 --exclude-dir=DIR1[,DIR2 ...]
326 Exclude the given comma separated directories from being scanned.
327 For example:
328
329 --exclude-dir=.cache,test
330
331 will skip all files that match "/.cache/" or "/test/" as part of
332 their path. Directories named ".bzr", ".cvs", ".hg", ".git", and
333 ".svn" are always excluded. This option only works with individual
334 directory names so including file path separators is not allowed.
335 Use --fullpath and --not-match-d=REGEX to supply a regex matching
336 multiple subdirectories.
337
338 --exclude-ext=EXT1[,EXT2 ...]
339 Do not count files having the given file name extensions.
340
341 --exclude-lang=L1[,L2[...]]
342 Exclude the given comma separated languages from being counted.
343
344 --exclude-list-file=FILE
345 Ignore files and/or directories whose names appear in FILE. FILE
346 should have one file name per line. Only exact matches are
347 ignored; relative path names will be resolved starting from the
348 directory where cloc is invoked. See also --list-file.
349
350 --fullpath
351 Modifies the behavior of --match-f or --not-match-f to include the
352 file's path in the regex, not just the file's basename. (This does
353 not expand each file to include its absolute path, instead it uses
354 as much of the path as is passed in to cloc.)
355
356 --include-ext=<ext1[,ext2[...]]>
357 Count only languages having the given comma separated file
358 extensions. Use --show-ext to see the recognized extensions.
359
360 --include-lang=L1[,L2 ...]
361 Count only the given comma separated languages L1, L2, L3, et
362 cetera.
363
364 --match-d=REGEX
365 Only count files in directories matching the Perl regex. For
366 example
367
368 --match-d='/(src|include)/'
369
370 only counts files in directory paths containing "/src/" or
371 "/include/".
372
373 --not-match-d=REGEX
374 Count all files except in directories matching the Perl regex.
375 Only the trailing directory name is compared, for example, when
376 counting in "/usr/local/lib", only "lib" is compared to the regex.
377 Add --fullpath to compare parent directories to the regex. Do not
378 include file path separators at the beginning or end of the regex.
379
380 --match-f=REGEX
381 Only count files whose basenames match the Perl regex. For example
382 this only counts files at start with Widget or widget:
383
384 --match-f='^[Ww]idget'
385
386 Add --fullpath to include parent directories in the regex instead
387 of just the basename.
388
389 --not-match-f=REGEX
390 Count all files except those whose basenames match the Perl regex.
391 Add --fullpath to include parent directories in the regex instead
392 of just the basename.
393
394 --skip-archive=REGEX
395 Ignore files that end with the given Perl regular expression. For
396 example, if given
397 --skip-archive='(zip|tar(\.(gz|Z|bz2|xz|7z))?)' the code will
398 skip files that end with .zip, .tar, .tar.gz, .tar.Z, .tar.bz2,
399 .tar.xz, and .tar.7z.
400
401 --skip-win-hidden
402 On Windows, ignore hidden files.
403
404 Debug Options
405 --categorized=FILE
406 Save names of categorized files to FILE.
407
408 --counted=FILE
409 Save names of processed source files to FILE.
410
411 --diff-alignment=FILE
412 Write to FILE a list of files and file pairs showing which files
413 were added, removed, and/or compared during a run with --diff.
414 This switch forces the --diff mode on.
415
416 --explain=LANG
417 Print the filters used to remove comments for language LANG and
418 exit. In some cases the filters refer to Perl subroutines rather
419 than regular expressions. An examination of the source code may be
420 needed for further explanation.
421
422 --help
423 Print cloc's internal usage information and exit.
424
425 --found=FILE
426 Save names of every file found to FILE.
427
428 --ignored=FILE
429 Save names of ignored files and the reason they were ignored to
430 FILE.
431
432 --print-filter-stages
433 Print to STDOUT processed source code before and after each filter
434 is applied.
435
436 --show-ext[=EXT]
437 Print information about all known (or just the given) file
438 extensions and exit.
439
440 --show-lang[=LANG]
441 Print information about all known (or just the given) languages and
442 exit.
443
444 --show-os
445 Print the value of the operating system mode and exit. See also
446 --unix, --windows.
447
448 -v[=N]
449 Turn on verbose with optional numeric value.
450
451 --verbose[=N]
452 Long form of -v.
453
454 --version
455 Print the version of this program and exit.
456
457 --write-lang-def=FILE
458 Writes to FILE the language processing filters then exits. Useful
459 as a first step to creating custom language definitions. Note:
460 languages which map to the same file extension will be excluded.
461 See also --force-lang-def, --read-lang-def.
462
463 --write-lang-def-incl-dup=FILE
464 Same as --write-lang-def, but includes duplicated extensions. This
465 generates a problematic language definition file because cloc will
466 refuse to use it until duplicates are removed.
467
468 Output Options
469 --3 Print third-generation language output. (This option can cause
470 report summation to fail if some reports were produced with this
471 option while others were produced without it.)
472
473 --by-percent X
474 Instead of comment and blank line counts, show these values as
475 percentages based on the value of X in the denominator:
476
477 X = 'c' -> # lines of code
478 X = 'cm' -> # lines of code + comments
479 X = 'cb' -> # lines of code + blanks
480 X = 'cmb' -> # lines of code + comments + blanks
481
482 For example, if using method 'c' and your code has twice as many
483 lines of comments as lines of code, the value in the comment column
484 will be 200%. The code column remains a line count.
485
486 --csv
487 Write the results as comma separated values.
488
489 --csv-delimiter=C
490 Use the character C as the delimiter for comma separated files
491 instead of ,. This switch forces --csv to be on.
492
493 --file-encoding=E
494 Write output files using the E encoding instead of the default
495 ASCII (E = 'UTF-7'). Examples: 'UTF-16', 'euc-kr', 'iso-8859-16'.
496 Known encodings can be printed with
497 perl -MEncode -e 'print join("\n", Encode->encodings(":all")),
498 "\n"'
499
500 --hide-rate
501 Do not show line and file processing rates in the output header.
502 This makes output deterministic.
503
504 --json
505 Write the results in JavaScript Object Notation (JSON).
506
507 --md
508 Write the results as Markdown-formatted text.
509
510 --out=FILE
511 Synonym for --report-file=FILE.
512
513 --progress-rate=N
514 Show progress update after every N files are processed (default
515 N=100). Set N to 0 to suppress progress output; useful when
516 redirecting output to STDOUT.
517
518 --quiet
519 Suppress all information messages except for the final report.
520
521 --report-file=FILE
522 Write the results to FILE instead of standard output.
523
524 --sql=FILE
525 Write results as SQL CREATE and INSERT statements which can be read
526 by a database program such as SQLite. If FILE is -, output is sent
527 to STDOUT.
528
529 --sql-append
530 Append SQL insert statements to the file specified by --sql and do
531 not generate table creation option.
532
533 --sql-project=NAME
534 Use name as the project identifier for the current run. Only valid
535 with the --sql option.
536
537 --sql-style=STYLE
538 Write SQL statements in the given style instead of the default
539 SQLite format. Styles include Oracle and Named_Columns.
540
541 --sum-one
542 For plain text reports, show the SUM: output line even if only one
543 input file is processed.
544
545 --xml
546 Write the results in XML.
547
548 --xsl[=FILE]
549 Reference FILE as an XSL stylesheet within the XML output. If FILE
550 is not given, writes a default stylesheet, cloc.xsl. This switch
551 forces --xml to be on.
552
553 --yaml
554 Write the results in YAML.
555
557 Count the lines of code in the Perl 5.10.0 compressed tar file on a
558 UNIX-like operating system:
559
560 cloc perl-5.10.0.tar.gz
561
562 Count the changes in files, code, and comments between Python releases
563 2.6.6 and 2.7:
564
565 cloc --diff Python-2.6.6.tar.bz Python-2.7.tar.bz2
566
567 To see how cloc aligns files for comparison between two code bases, use
568 the --diff-alignment=FILE option. Here the alignment information is
569 written to "align.txt":
570
571 cloc --diff-aligment=align.txt gcc-4.4.0.tar.bz2 gcc-4.5.0.tar.bz2
572
573 Count file, code, and comment changes between two git commits:
574
575 cloc --git --diff b409850824 HEAD
576
577 Print the recognized languages:
578
579 cloc --show-lang
580
581 Remove comments from "foo.c" and save the result in "foo.c.nc" ("nc" is
582 an arbitrary extension; used here to denote "no comments"):
583
584 cloc --strip-comments=nc foo.c
585
586 Additional examples can be found at <https://github.com/AlDanial/cloc>.
587
589 None.
590
592 None.
593
595 sloccount(1)
596
598 The cloc program was written by Al Danial <al.danial@gmail.com> and is
599 Copyright (C) 2006-2019 <al.danial@gmail.com>.
600
601 The manual page was originally written by Jari Aalto
602 <jari.aalto@cante.net>.
603
604 Both the code and documentation is released under the GNU GPL version 2
605 or (at your option) any later version. For more information about
606 license, visit <http://www.gnu.org/copyleft/gpl.html>.
607
608
609
610cloc 2021-02-14 cloc(1)