# cloc

 Developer Jari Aalto Version 1.76 Release Date 2018-02-09 Package Size 245KB Installed Size 972KB

## 摘要

### 介绍

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

### 特点

• Count all lines of source codes.
• Recognize the programming language by files extension.
• Seperate source codes and comments based on programming languages.
• Support various output formats like csv, sql xml, xsl and yaml.

## 如何安装

### 依赖

• libalgorithm-diff-perl
• module to find differences between files
• libregexp-common-perl
• module with common regular expressions
• perl













### 安装的软件包

• cloc
• libregexp-common-perl

### 检查

cloc --version 1.60  ## 如何使用 ### 结构 cloc [选项] <文件|目录|Git hash(es)> | <set 1> <set 2> | <要保存的文件>  ### 选项 基于版本1.76创建。 • --extract-with=CMD This option is only needed if cloc is unable to figure out how to extract the contents of the input file(s) by itself. Use CMD to extract binary archive files (e.g.: .tar.gz, .zip, .Z). Use the literal '>FILE<' as a stand-in for the actual file(s) to be extracted. For example, to count lines of code in the input files gcc-4.2.tar.gz perl-5.8.8.tar.gz on Unix use --extract-with='gzip -dc >FILE< | tar xf -' or, if you have GNU tar, --extract-with='tar zxf >FILE<' and on Windows use, for example(if WinZip is installed there) --extract-with="\"c:\Program Files\WinZip\WinZip32.exe\" -e -o >FILE< ." • --list-file=FILE Take the list of file and/or directory names to process from FILE, which has one file/directory name per line. Only exact matches are counted; relative path names will be resolved starting from the directory where cloc is invoked. See also --exclude-list-file. • --vcs=VCS Invoke a system call to VCS to obtain a list of files to work on. If VCS is 'git', then will invoke 'git ls-files' to get a file list and 'git submodule status' to get a list of submodules whose contents will be ignored. See also --git which accepts git commit hashes and branch names. If VCS is 'svn' then will invoke 'svn list -R'. The primary benefit is that cloc will then skip files explicitly excluded by the versioning tool in question, ie, those in .gitignore or have the svn:ignore property. Alternatively VCS may be any system command that generates a list of files. Note: cloc must be in a directory which can read the files as they are returned by VCS. cloc will not download files from remote repositories. 'svn list -R' may refer to a remote repository to obtain file names (and therefore may require authentication to the remote repository), but the files themselves must be local. • --unicode Check binary files to see if they contain Unicode expanded ASCII text. This causes performance to drop noticeably. #### Processing Options • --autoconf Count .in files (as processed by GNU autoconf) of recognized languages. See also --no-autogen. • --by-file Report results for every source file encountered. • --by-file-by-lang Report results for every source file encountered in addition to reporting by language. • --count-and-diff SET1 SET2 First perform direct code counts of source file(s) of SET1 and SET2 separately, then perform a diff of these. Inputs may be pairs of files, directories, or archives. If --out or --report-file is given, three output files will be created, one for each of the two counts and one for the diff. See also --diff, --diff-alignment, --diff-timeout, --ignore-case, --ignore-whitespace. • --diff SET1 SET2 Compute differences in code and comments between source file(s) of SET1 and SET2. The inputs may be any mix of files, directories, archives, or git commit hashes (Unix only). Use --diff-alignment to generate a list showing which file pairs where compared. See also --count-and-diff, --diff-alignment, --diff-timeout, --ignore-case, --ignore-whitespace. • --diff-timeout N Ignore files which take more than N seconds to process. Default is 10 seconds. (Large files with many repeated lines can cause Algorithm::Diff::sdiff() to take hours.) • --follow-links [Unix only] Follow symbolic links to directories (sym links to files are always followed). • --force-lang=LANG,EXT Process all files that have a EXT extension with the counter for language LANG. For example, to count all .f files with the Fortran 90 counter (which expects files to end with .f90) instead of the default Fortran 77 counter, use --force-lang="Fortran 90",f If EXT is omitted, every file will be counted with the LANG counter. This option can be specified multiple times (but that is only useful when EXT is given each time). See also --script-lang, --lang-no-ext. • --force-lang-def=FILE Load language processing filters from FILE, then use these filters instead of the built-in filters. Note: languages which map to the same file extension (for example: MATLAB/Mathematica/Objective C/MUMPS/Mercury; Pascal/PHP; Lisp/OpenCL; Lisp/Julia; Perl/Prolog) will be ignored as these require additional processing that is not expressed in language definition files. Use --read-lang-def to define new language filters without replacing built-in filters (see also --write-lang-def). • --git Forces the inputs to be interpreted as git targets (commit hashes, branch names, et cetera) if these are not first identified as file or directory names. This option overrides the --vcs=git logic if this is given; in other words, --git gets its list of files to work on directly from git using the hash or branch name rather than from 'git ls-files'. This option can be used with --diff to perform line count diffs between git commits, or between a git commit and a file, directory, or archive. Use -v/--verbose to see the git system commands cloc issues. • --ignore-whitespace Ignore horizontal white space when comparing files with --diff. See also --ignore-case. • --ignore-case Ignore changes in case; consider upper- and lower- case letters equivalent when comparing files with --diff. See also --ignore-whitespace. • --lang-no-ext=LANG Count files without extensions using the LANG counter. This option overrides internal logic for files without extensions (where such files are checked against known scripting languages by examining the first line for #!). See also --force-lang, --script-lang. • --max-file-size=MB Skip files larger than MB megabytes when traversing directories. By default, MB=100. cloc's memory requirement is roughly twenty times larger than the largest file so running with files larger than 100 MB on a computer with less than 2 GB of memory will cause problems. Note: this check does not apply to files explicitly passed as command line arguments. • --no-autogen[=list] Ignore files generated by code-production systems such as GNU autoconf. To see a list of these files (then exit), run with --no-autogen list See also --autoconf. • --original-dir [Only effective in combination with --strip-comments] Write the stripped files to the same directory as the original files. • --read-binary-files Process binary files in addition to text files. This is usually a bad idea and should only be attempted with text files that have embedded binary data. • --read-lang-def=FILE Load new language processing filters from FILE and merge them with those already known to cloc. If FILE defines a language cloc already knows about, cloc's definition will take precedence. Use --force-lang-def to override cloc's definitions (see also --write-lang-def ). • --script-lang=LANG,S Process all files that invoke S as a #! scripting language with the counter for language LANG. For example, files that begin with #!/usr/local/bin/perl5.8.8 will be counted with the Perl counter by using --script-lang=Perl The language name is case insensitive but the name of the script language executable, S, must have the right case. This option can be specified multiple times. See also --force-lang, --lang-no-ext. • --sdir=DIR Use DIR as the scratch directory instead of letting :Temp chose the location. Files written to this location are not removed at the end of the run (as they are with :Temp). • --skip-uniqueness Skip the file uniqueness check. This will give a performance boost at the expense of counting files with identical contents multiple times (if such duplicates exist). • --stdin-name=FILE Give a file name to use to determine the language for standard input. (Use - as the input name to receive source code via STDIN.) • --strip-comments=EXT For each file processed, write to the current directory a version of the file which has blank and commented lines removed inline comments persist). The name of each stripped file is the original file name with .EXT appended to it. It is written to the current directory unless --original-dir is on. • --sum-reports Input arguments are report files previously created with the --report-file option. Makes a cumulative set of results containing the sum of data from the individual report files. • --processes=NUM [Available only on systems with a recent version of the Parallel::ForkManager module. Not available on Windows.] Sets the maximum number of cores that cloc uses. The default value of 0 disables multiprocessing. • --unix Override the operating system autodetection logic and run in UNIX mode. See also --windows, --show-os. • --use-sloccount If SLOCCount is installed, use its compiled executables c_count, java_count, pascal_count, php_count, and xml_count instead of cloc's counters. SLOCCount's compiled counters are substantially faster than cloc's and may give a performance improvement when counting projects with large files. However, these cloc-specific features will not be available: --diff, --count-and-diff, --strip-comments, --unicode. • --windows Override the operating system autodetection logic and run in Microsoft Windows mode. See also --unix, --show-os. #### Filter Options • --exclude-dir=D1[,D2,] Exclude the given comma separated directories D1, D2, D3, et cetera, from being scanned. For example --exclude-dir=.cache,test will skip all files and subdirectories that have .cache or test as their parent directory. Directories named .bzr, .cvs, .hg, .git, .svn, and .snapshot are always excluded. This option only works with individual directory names so including file path separators is not allowed. Use --fullpath and --not-match-d=REGEX to supply a regex matching multiple subdirectories. • --exclude-ext=EXT1[,EXT2[...]] Do not count files having the given file name extensions. • --exclude-lang=L1[,L2,] Exclude the given comma separated languages L1, L2, L3, et cetera, from being counted. • --exclude-list-file=FILE Ignore files and/or directories whose names appear in FILE. FILE should have one file name per line. Only exact matches are ignored; relative path names will be resolved starting from the directory where cloc is invoked. See also --list-file. • --fullpath Modifies the behavior of --match-f, --not-match-f, and --not-match-d to include the file's path in the regex, not just the file's basename. (This does not expand each file to include its absolute path, instead it uses as much of the path as is passed in to cloc.) Note: --match-d always looks at the full path and therefore is unaffected by --fullpath. • --include-lang=L1,[,L2,] Count only the given comma separated languages L1, L2, L3, et cetera. • --match-d=REGEX Only count files in directories matching the Perl regex. For example --match-d='(src|include)' only counts files in directories containing src or include. Unlike --not-match-d, --match-f, and --not-match-f, --match-d always compares the fully qualified path against the regex. • --not-match-d=REGEX Count all files except those in directories matching the Perl regex. Only the trailing directory name is compared, for example, when counting in /usr/local/lib, only 'lib' is compared to the regex. Add --fullpath to compare parent directories to the regex. Do not include file path separators at the beginning or end of the regex. • --match-f=REGEX Only count files whose basenames match the Perl regex. For example --match-f='^[Ww]idget' only counts files that start with Widget or widget. Add --fullpath to include parent directories in the regex instead of just the basename. • --not-match-f=REGEX Count all files except those whose basenames match the Perl regex. Add --fullpath to include parent directories in the regex instead of just the basename. • --skip-archive=REGEX Ignore files that end with the given Perl regular expression. For example, if given --skip-archive=(zip|tar(.(gz|Z|bz2|xz|7z))?)' the code will skip files that end with .zip, .tar, .tar.gz, .tar.Z, .tar.bz2, .tar.xz, and .tar.7z. • --skip-win-hidden On Windows, ignore hidden files. #### Debug Options • --categorized=FILE Save names of categorized files to FILE. • --counted=FILE Save names of processed source files to FILE. • --diff-alignment=FILE Write to FILE a list of files and file pairs showing which files were added, removed, and/or compared during a run with --diff. This switch forces the --diff mode on. • --explain=LANG Print the filters used to remove comments for language LANG and exit. In some cases the filters refer to Perl subroutines rather than regular expressions. An examination of the source code may be needed for further explanation. • --help Print this usage information and exit. • --found=FILE Save names of every file found to FILE. • --ignored=FILE Save names of ignored files and the reason they were ignored to FILE. • --print-filter-stages Print processed source code before and after each filter is applied. • --show-ext[=EXT] Print information about all known (or just the given) file extensions and exit. • --show-lang[=LANG] Print information about all known (or just the given) languages and exit. • --show-os Print the value of the operating system mode and exit. See also --unix, --windows. • -v[=N] Verbose switch (optional numeric value). • -verbose[=N] Long form of -v. • --version Print the version of this program and exit. • --write-lang-def=FILE Writes to FILE the language processing filters then exits. Useful as a first step to creating custom language definitions (see also --force-lang-def, --read-lang-def). #### Output Options • --3 Print third-generation language output. (This option can cause report summation to fail if some reports were produced with this option while others were produced without it.) • --by-percent X Instead of comment and blank line counts, show these values as percentages based on the value of X in the denominator: X = 'c' -> # lines of code X = 'cm' -> # lines of code + comments X = 'cb' -> # lines of code + blanks X = 'cmb' -> # lines of code + comments + blanks For example, if using method 'c' and your code has twice as many lines of comments as lines of code, the value in the comment column will be 200%. The code column remains a line count. • --csv Write the results as comma separated values. • --csv-delimiter=C Use the character C as the delimiter for comma separated files instead of ,. This switch forces • --json Write the results as JavaScript Object Notation (JSON) formatted output. • --md Write the results as Markdown-formatted text. • --out=FILE Synonym for --report-file=FILE. • --progress-rate=N Show progress update after every N files are processed (default N=100). Set N to 0 to suppress progress output (useful when redirecting output to STDOUT). • --quiet Suppress all information messages except for the final report. • --report-file=FILE Write the results to FILE instead of STDOUT. • --sql=FILE Write results as SQL create and insert statements which can be read by a database program such as SQLite. If FILE is -, output is sent to STDOUT. • --sql-append Append SQL insert statements to the file specified by --sql and do not generate table creation statements. Only valid with the --sql option. • --sql-project=NAME Use NAME as the project identifier for the current run. Only valid with the --sql option. • --sql-style=STYLE Write SQL statements in the given style instead of the default SQLite format. Currently, the only style option is Oracle. • --sum-one For plain text reports, show the SUM: output line even if only one input file is processed. • --xml Write the results in XML. • --xsl=FILE Reference FILE as an XSL stylesheet within the XML output. If FILE is 1 (numeric one), writes a default stylesheet, cloc.xsl (or cloc-diff.xsl if --diff is also given). This switch forces --xml on. • --yaml Write the results in YAML. ### 例子 #### Simply use  cloc Linux-Command.org

     123 text files.
122 unique files.
110 files ignored.

github.com/AlDanial/cloc v 1.74  T=0.42 s (35.5 files/s, 4450.4 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Lisp                             4             84             46            588
HTML                             3             40            294            438
Bourne Shell                     1             23              2            122
make                             2             15              0             88
YAML                             2              2              0             66
Dockerfile                       1              4              2             32
CSS                              1              1              0             24
JavaScript                       1              0              0             11
-------------------------------------------------------------------------------
SUM:                            15            169            344           1369
-------------------------------------------------------------------------------


Not classified org files.

$cloc Linux-Command.org --force-lang="Bourne Again Shell,org"   123 text files. 122 unique files. 13 files ignored. github.com/AlDanial/cloc v 1.74 T=0.54 s (209.2 files/s, 37307.1 lines/s) -------------------------------------------------------------------------------- Language files blank comment code -------------------------------------------------------------------------------- Bourne Again Shell 97 1976 9412 6703 Lisp 4 84 46 588 HTML 3 40 294 438 Bourne Shell 1 23 2 122 make 2 15 0 88 YAML 2 2 0 66 Dockerfile 1 4 2 32 CSS 1 1 0 24 JavaScript 1 0 0 11 -------------------------------------------------------------------------------- SUM: 112 2145 9756 8072 --------------------------------------------------------------------------------  Forced classification the org files as Bourne Again Shell(Because bash has same comment method). #### with Git hash 请参阅--git选项。 $ cloc Linux-Command.org --git 5e5512b --force-lang="Bourne Again Shell,org"

       1 text file.
1 unique file.
0 files ignored.

github.com/AlDanial/cloc v 1.74  T=0.05 s (19.1 files/s, 19.1 lines/s)
--------------------------------------------------------------------------------
Language                      files          blank        comment           code
--------------------------------------------------------------------------------
Bourne Again Shell                1              0              1              0
--------------------------------------------------------------------------------


Can classificate using git hash.

• Used first commit of Linux-Commands.org

## 参考

Date: 2018-02-29

Created: 2018-12-10 Mon 03:15

Validate