需要去统计
前端 ReactJS的Antd Pro的html,css,js

后端Django的python

的代码的行数
且其中需要排除其他某些特定文件夹:
比如antd pro中的测试的e2e:

.vscode:

logs

去找找mac中如何使用命令去实现效果
mac 统计代码行数
试了:
➜ xxx git:(master) $ find . "(" -name "*.m" -or -name "*.mm" -or -name "*.cpp" -or -name "*.h" -or -name "*.rss" ")" -print | xargs wc -l zsh: command not found: $ ➜ xxx git:(master) find . "(" -name "*.m" -or -name "*.mm" -or -name "*.cpp" -or -name "*.h" -or -name "*.rss" ")" -print | xargs wc -l
都没用。
➜ xxx git:(master) find . -name "*.m" -or -name "*.h" -or -name "*.xib" -or -name "*.c" |xargs grep -v "^$"|wc -l 0 ➜ xxx git:(master) find . -name "*.py" -or -name "*.conf" -or -name "*.env" | xargs grep -v "^$" | wc -l 3200 ➜ xxx git:(master) find . -name "*.py" -or -name "*.conf" | xargs grep -v "^$" | wc -l 3170 ➜ xxx git:(master) find . -name "*.py" | xargs grep -v "^$" | wc -l 3139
python的py有3000多行
前端:
➜ src git:(master) ✗ find . -name "*.js" -or -name "*.less" | xargs grep -v "^$" | wc -l 18094
有1万8千行
-》很多都是模板的代码。不是实际的代码
想要排除某些文件夹,这种方式不支持。
cloc支持排除目录
去试试
➜ xxxWeb git:(master) ✗ brew install cloc Updating Homebrew... ==> Downloading https://homebrew.bintray.com/bottles/cloc-1.76.high_sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring cloc-1.76.high_sierra.bottle.tar.gz 🍺 /usr/local/Cellar/cloc/1.76: 87 files, 1.5MB
去看看用法:
➜ xxxWeb git:(master) ✗ cloc --help Usage: cloc [options] <file(s)/dir(s)/git hash(es)> | <set 1> <set 2> | <report files> Count, or compute differences of, physical lines of source code in the given files (may be archives such as compressed tarballs or zip files, or git commit hashes or branch names) and/or recursively below the given directories. Input Options --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: --extract-with="\"c:\Program Files\WinZip\WinZip32.exe\" -e -o >FILE< ." (if WinZip is installed there). --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. 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 over-ride 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,perl5.8.8 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 File::Temp chose the location. Files written to this location are not removed at the end of the run (as they are with File::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 (in-line 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.




ithub.com/AlDanial/cloc v 1.76 T=93.30 s (347.6 files/s, 60320.7 lines/s) --------------------------------------------------------------------------------------- Language files blank comment code --------------------------------------------------------------------------------------- JavaScript 21465 432384 593168 2726715 JSON 5326 1367 0 990394 Markdown 2541 106115 2 264094 TypeScript 1668 21669 78082 168223 HTML 167 50035 110 64842 CSS 220 487 1043 64699 LESS 555 3439 972 25510 XML 36 241 13 7757 C/C++ Header 21 1144 341 5869 YAML 245 185 317 5138 CoffeeScript 58 1519 369 4281 Bourne Shell 20 182 139 970 make 34 286 187 871 JSX 36 121 89 733 Python 3 175 187 723 Windows Module Definition 6 111 0 608 C++ 7 70 36 317 Groovy 1 53 14 280 Handlebars 4 60 0 225 Bourne Again Shell 4 36 22 214 D 5 0 0 71 DOS Batch 2 24 2 66 OCaml 1 23 104 29 Sass 1 5 0 19 diff 1 2 24 18 Lisp 1 0 0 6 --------------------------------------------------------------------------------------- SUM: 32428 619733 675221 4332672 ---------------------------------------------------------------------------------------
现在去排除一些文件夹
➜ src git:(master) ✗ pwd /Users/crifan/dev/dev_root/company/xxx/projects/xxx/web/xxxWeb/src ➜ src git:(master) ✗ cloc ./ --exclude-dir=e2e,assets 201 text files. 200 unique files. 3 files ignored. github.com/AlDanial/cloc v 1.76 T=1.09 s (182.4 files/s, 18122.7 lines/s) ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- JavaScript 145 1481 744 14576 LESS 54 248 18 2703 ------------------------------------------------------------------------------- SUM: 199 1729 762 17279 -------------------------------------------------------------------------------
继续排除其他子文件夹

结果出错:
➜ src git:(master) ✗ cloc ./ --exclude-dir=e2e,assets,routes/Dashboard,routes/List --exclude-dir 'routes/List' : cannot specify directory paths --exclude-dir 'routes/Dashboard' : cannot specify directory paths Use '--fullpath --not-match-d=REGEX' instead Died at /usr/local/Cellar/cloc/1.76/libexec/bin/cloc line 710.
想要搜:
cannot specify directory paths
突然发现:
中写了:
“–exclude-dir=<D1>[,D2,] Exclude the given comma separated directories D1, D2, D3, et cetera, frombeing scanned. For example –exclude-dir=.cache,test will skip all files andsubdirectories that have /.cache/or/test/ astheir parent directory. Directories named .bzr, .cvs, .hg, .git, and.svn are always excluded. This option only works withindividual directory names so including file path separators isnotallowed. Use –fullpath and–not-match-d=<regex> to supply a regex matching multiple subdirectories.”
结果用:
➜ src git:(master) ✗ cloc ./ --fullpath --not-match-d=routes/Dashboard,routes/List --exclude-dir=e2e,assets,routes/Dashboard,routes/List --exclude-dir 'routes/Dashboard' : cannot specify directory paths --exclude-dir 'routes/List' : cannot specify directory paths Use '--fullpath --not-match-d=REGEX' instead Died at /usr/local/Cellar/cloc/1.76/libexec/bin/cloc line 710.
还是出错。
➜ src git:(master) ✗ cloc ./ --fullpath --not-match-d routes/Dashboard routes/List --exclude-dir=e2e,assets,routes/Dashboard,routes/List --exclude-dir 'routes/List' : cannot specify directory paths --exclude-dir 'routes/Dashboard' : cannot specify directory paths Use '--fullpath --not-match-d=REGEX' instead Died at /usr/local/Cellar/cloc/1.76/libexec/bin/cloc line 710.
cloc –not-match-d
试试只有一个要排除的路径,错误依旧:
➜ src git:(master) ✗ cloc ./ --fullpath --not-match-d routes/List --exclude-dir=e2e,assets,routes/Dashboard,routes/List --exclude-dir 'routes/Dashboard' : cannot specify directory paths --exclude-dir 'routes/List' : cannot specify directory paths Use '--fullpath --not-match-d=REGEX' instead Died at /usr/local/Cellar/cloc/1.76/libexec/bin/cloc line 710.
以及:
➜ src git:(master) ✗ cloc ./ --fullpath --not-match-d=routes/List --exclude-dir=e2e,assets,routes/Dashboard,routes/List --exclude-dir 'routes/Dashboard' : cannot specify directory paths --exclude-dir 'routes/List' : cannot specify directory paths Use '--fullpath --not-match-d=REGEX' instead Died at /usr/local/Cellar/cloc/1.76/libexec/bin/cloc line 710.
看来是regex搞错了。
终于找到一个参考的regex的写法:
--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.
去试试
➜ src git:(master) ✗ cloc ./ --fullpath --not-match-d='/(routes/(Dashboard|List))/' --exclude-dir=e2e,assets,routes/Dashboard,routes/List --exclude-dir 'routes/Dashboard' : cannot specify directory paths --exclude-dir 'routes/List' : cannot specify directory paths Use '--fullpath --not-match-d=REGEX' instead Died at /usr/local/Cellar/cloc/1.76/libexec/bin/cloc line 710.
cloc how write regex
用\/去转义/,还是不行:
➜ src git:(master) ✗ cloc ./ --fullpath --not-match-d='/(routes\/(Dashboard|List))/' --exclude-dir=e2e,assets,routes/Dashboard,routes/List --exclude-dir 'routes/List' : cannot specify directory paths --exclude-dir 'routes/Dashboard' : cannot specify directory paths Use '--fullpath --not-match-d=REGEX' instead Died at /usr/local/Cellar/cloc/1.76/libexec/bin/cloc line 710.
试试两个//
➜ src git:(master) ✗ cloc ./ --fullpath --not-match-d='/(routes//(Dashboard|List))/' --exclude-dir=e2e,assets,routes/Dashboard,routes/List --exclude-dir 'routes/List' : cannot specify directory paths --exclude-dir 'routes/Dashboard' : cannot specify directory paths Use '--fullpath --not-match-d=REGEX' instead Died at /usr/local/Cellar/cloc/1.76/libexec/bin/cloc line 710.
问题依旧。
cloc regex contain slash
后来发现自己搞错了,没有去掉之前的问题:
➜ src git:(master) ✗ cloc ./ --fullpath --not-match-d='/(routes/(Dashboard|List))/' --exclude-dir=e2e,assets 201 text files. 200 unique files. 3 files ignored. github.com/AlDanial/cloc v 1.76 T=1.11 s (179.8 files/s, 17861.0 lines/s) ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- JavaScript 145 1481 744 14576 LESS 54 248 18 2703 ------------------------------------------------------------------------------- SUM: 199 1729 762 17279 -------------------------------------------------------------------------------
【总结】
【普通需求:只是统计某文件夹下某一种或几种语言代码的行数】
想要去统计某个文件夹下面所有的某种类型代码的行数:
(1)用组合命令:find+xargs+wc
比如:
python的:
find . -name "*.py" | xargs grep -v "^$" | wc -l
html的
find . -name "*.html" | xargs grep -v "^$" | wc -l
多种(语言)文件名后缀:
find . -name "*.js" -or -name "*.css" -or -name "*.html"| xargs grep -v "^$" | wc -l find . -name "*.py" -or -name "*.conf" -or -name "*.md"| xargs grep -v "^$" | wc -l
(2)用cloc:
cloc ./
比如:
➜ xxx git:(master) cloc ./ 52 text files. 50 unique files. 24 files ignored. github.com/AlDanial/cloc v 1.76 T=1.07 s (32.8 files/s, 5005.8 lines/s) ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- Python 13 311 307 1446 HTML 3 64 122 1319 XML 9 0 0 1111 Markdown 2 95 0 430 JSON 8 0 0 143 ------------------------------------------------------------------------------- SUM: 35 470 429 4449 -------------------------------------------------------------------------------
【高级需求:统计某文件夹下,排除某些文件夹时,某些语言的代码的行数】
此处在:
/Users/crifan/dev/dev_root/company/xxx/projects/xxx/web/xxxWeb/src
想要排除:
routes/Dashboard
routes/List
以及
e2e
assets
文件夹
然后对应的写法是:
cloc ./ --fullpath --not-match-d='/(routes/(Dashboard|List))/' --exclude-dir=e2e,assets
即可统计出结果:(js+less)17279行代码。
【后记】
对于有些稍微复杂一点的需求,(或许是 自己参数设置的有问题,而导致)结果不太准:
想要排除相关文件夹:

去试试:
cloc ./ --fullpath --exclude-dir=js/bootstrap-4.1.3,js/jquery-3.3.1,css/bootstrap-4.1.3,css/font-awesome-4.7.0,css/highlight
结果:
➜ xxxWeb git:(master) cloc ./ --fullpath --exclude-dir=js/bootstrap-4.1.3,js/jquery-3.3.1,css/bootstrap-4.1.3,css/font-awesome-4.7.0,css/highlight --exclude-dir 'js/jquery-3.3.1' : cannot specify directory paths --exclude-dir 'js/bootstrap-4.1.3' : cannot specify directory paths --exclude-dir 'css/bootstrap-4.1.3' : cannot specify directory paths --exclude-dir 'css/highlight' : cannot specify directory paths --exclude-dir 'css/font-awesome-4.7.0' : cannot specify directory paths Use '--fullpath --not-match-d=REGEX' instead Died at /usr/local/Cellar/cloc/1.76/libexec/bin/cloc line 710.
然后换用:
cloc ./ --fullpath --exclude-dir=bootstrap-4.1.3,jquery-3.3.1,font-awesome-4.7.0,highlight
结果:
➜ xxxWeb git:(master) cloc ./ --fullpath --exclude-dir=bootstrap-4.1.3,jquery-3.3.1,font-awesome-4.7.0,highlight 11 text files. 11 unique files. 3 files ignored. github.com/AlDanial/cloc v 1.76 T=1.03 s (10.7 files/s, 1546.1 lines/s) ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- JavaScript 5 170 216 650 CSS 3 78 48 232 HTML 2 37 52 69 Markdown 1 19 0 25 ------------------------------------------------------------------------------- SUM: 11 304 316 976 -------------------------------------------------------------------------------
虽然可以运行,但是结果明显不对:
我此处虽然2,3个js文件的代码,就超过650行了。。。
算了,还不如手动统计呢。。
js/book_common.js 270 js/book_detail.js 247 js/main.js 235 js/util.js 284 book_detail.html 72 index.html 86 css/main.css 103 css/book_detail.css 168 css/book_common.css 87
加起来:
- js:1036
- html::158
- css:358
共:1552
【后记 20200108】
在另外一台mac上安装:
brew install cloc Updating Homebrew... ==> Auto-updated Homebrew! Updated 2 taps (homebrew/core and homebrew/cask). ==> New Formulae bandwhich cgns komposition poetry yaegi ==> Updated Formulae leptonica ✔ cppad frpc ilmbase msmtp picard-tools swiftlint pyenv ✔ ctl frps imagemagick nano pipx syncthing ack ctop gatsby-cli imagemagick@6 ncompress poppler synfig acpica deno gcsfuse jdupes ndpi pre-commit taskell aliyun-cli diff-pdf gdb jenkins nethack primesieve teleport ansible django-completion ghq jfrog-cli-go nift proj terrahub ansible-lint dmd gimme-aws-creds jpeg-turbo node-build prometheus tmuxinator appium docfx git-annex juju-wait now-cli pstoedit tmuxinator-completion aptly docker-compose git-lfs k3d ntl ranger toast arduino-cli docker-credential-helper-ecr git-quick-stats kubeprod ocrmypdf rav1e topgrade ask-cli dub gitmoji languagetool onefetch rawtoaces tunnel awscli duck glassfish ldc opa re2 uhd azure-cli dune glfw lerna opencv remind ultralist ballerina dvc global libarchive opencv@2 rex vim basex easyengine glooctl libetonyek opencv@3 run vips caffe ejdb glslang librealsense openexr securefs visp ccache elvish gmsh libsixel openimageio serverless wal2json cdk embree gnuradio liquibase opensc singular watch cereal entr google-authenticator-libpam maxwell openvdb siril weechat certigo exploitdb gr-osmosdr mdds paket smartmontools whois chakra eye-d3 grep mercurial pandoc socat wxmaxima citus ffmpeg grin midnight-commander passwdqc sourcekitten xmrig click ffsend grin-wallet mill pcsc-lite sqlmap yamllint coffeescript field3d handbrake minio pdftoipe starship yle-dl cointop flow help2man minio-mc peco subversion you-get collectd fn hugo mmark perl swagger-codegen youtube-dl conjure-up freetds icecast mpd phpstan swiftformat ==> Deleted Formulae node@8 ✔ hg-flow leafnode mysql-utilities pygobject pygtkglext qriollo srclib vte diffuse ipython@5 libagar np2 pygtk pygtksourceview redo terminator zim ==> Downloading https://homebrew.bintray.com/bottles/cloc-1.84.mojave.bottle.tar.gz ==> Downloading from https://akamai.bintray.com/fa/faa85a918f0517f35a41fb60550c0d990ed58aed325c50efca95634b014edbd8?__gda__=exp=1578448924~hmac=f64c568e5795df8846ecb0b5ad37019420a9ded73d37701767de9ba311888fcb& ######################################################################## 100.0% ==> Pouring cloc-1.84.mojave.bottle.tar.gz 🍺 /usr/local/Cellar/cloc/1.84: 89 files, 1.6MB ==> `brew cleanup` has not been run in 30 days, running now... Removing: /Users/xxx/Library/Caches/Homebrew/leptonica--1.78.0_1.mojave.bottle.tar.gz... (2.4MB) Removing: /Users/xxx/Library/Caches/Homebrew/mitmproxy--5.0.0.mojave.bottle.tar.gz... (7.5MB) Removing: /Users/xxx/Library/Caches/Homebrew/mongodb-community--4.2.1.tgz... (104MB) Removing: /usr/local/Cellar/protobuf/3.10.0... (268 files, 19.5MB) Removing: /Users/xxx/Library/Caches/Homebrew/python--3.7.5.mojave.bottle.tar.gz... (14.8MB) Removing: /Users/xxx/Library/Caches/Homebrew/tesseract--4.1.0.mojave.bottle.tar.gz... (11.8MB) Removing: /Users/xxx/Library/Logs/Homebrew/pyenv... (64B) Removing: /Users/xxx/Library/Logs/Homebrew/pkg-config... (64B) Removing: /Users/xxx/Library/Logs/Homebrew/libtiff... (64B) Removing: /Users/xxx/Library/Logs/Homebrew/mongodb-community... (126B) Removing: /Users/xxx/Library/Logs/Homebrew/little-cms2... (64B) Removing: /Users/xxx/Library/Logs/Homebrew/libpng... (64B) Removing: /Users/xxx/Library/Logs/Homebrew/gdbm... (64B) Removing: /Users/xxx/Library/Logs/Homebrew/mitmproxy... (64B) Removing: /Users/xxx/Library/Logs/Homebrew/python... (3 files, 141.7KB) Removing: /Users/xxx/Library/Logs/Homebrew/openjpeg... (64B) Removing: /Users/xxx/Library/Logs/Homebrew/readline... (64B) Removing: /Users/xxx/Library/Logs/Homebrew/tesseract... (64B) Removing: /Users/xxx/Library/Logs/Homebrew/webp... (64B) Removing: /Users/xxx/Library/Logs/Homebrew/sqlite... (64B) Removing: /Users/xxx/Library/Logs/Homebrew/xz... (64B) Removing: /Users/xxx/Library/Logs/Homebrew/giflib... (64B) Removing: /Users/xxx/Library/Logs/Homebrew/autoconf... (64B) Removing: /Users/xxx/Library/Logs/Homebrew/leptonica... (64B) Removing: /Users/xxx/Library/Logs/Homebrew/jpeg... (64B) Removing: /Users/xxx/Library/Logs/Homebrew/mongodb-community-shell... (132B) Removing: /Users/xxx/Library/Logs/Homebrew/protobuf... (64B)
使用:
xxx@xxx ~/dev/xx/crawler/appAutoCrawler/AppCrawler master cloc . 304 text files. 301 unique files. 199 files ignored. github.com/AlDanial/cloc v 1.84 T=7.07 s (17.5 files/s, 6643.0 lines/s) ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- JSON 21 0 0 32963 Python 70 1373 1787 8590 XML 15 0 0 1061 Java 2 27 111 330 Markdown 2 125 0 299 HTML 2 12 0 124 YAML 1 19 41 63 DOS Batch 10 0 0 30 JavaScript 1 0 0 3 ------------------------------------------------------------------------------- SUM: 124 1556 1939 43463 -------------------------------------------------------------------------------
和:
xxx@xxx ~/dev/zzz/crawler/appAutoCrawler/AppCrawler master cloc . --exclude-dir=tool,tmp,task,logging,gameAutomation,debug,data 69 text files. 69 unique files. 6 files ignored. github.com/AlDanial/cloc v 1.84 T=0.25 s (260.4 files/s, 41672.9 lines/s) ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- Python 50 1065 1498 7350 Markdown 1 122 0 294 JSON 3 0 0 79 YAML 1 19 41 63 DOS Batch 10 0 0 30 JavaScript 1 0 0 3 ------------------------------------------------------------------------------- SUM: 66 1206 1539 7819 -------------------------------------------------------------------------------
效果不错。
【20200923】
✘ xxx@xxx ~/dev/xxx/crawler/appAutoCrawler/AppCrawler master ● cloc . --exclude-dir=tool,tmp,task,logging,gameAutomation,debug,data 5933 text files. 5281 unique files. Complex regular subexpression recursion limit (32766) exceeded at /usr/local/Cellar/cloc/1.84/libexec/bin/cloc line 9879. 1650 files ignored. github.com/AlDanial/cloc v 1.84 T=31.71 s (140.2 files/s, 60137.3 lines/s) ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- Python 3544 233602 337838 969246 C 6 14346 64534 126027 Objective C 239 8850 5942 35361 XML 41 0 11 32593 C/C++ Header 401 6384 23419 26873 JavaScript 30 569 325 2612 XSLT 7 609 1108 2347 Cython 21 304 125 2311 reStructuredText 17 587 244 1540 Markdown 27 580 0 1372 CSS 6 8 17 1370 SQL 4 3 0 1129 SVG 2 0 0 934 PO File 4 161 188 545 YAML 10 62 123 545 JSON 23 7 0 441 HTML 14 33 21 423 Fortran 90 15 69 35 252 Bourne Shell 12 24 16 198 Protocol Buffers 1 10 0 83 Fish Shell 1 18 15 69 PowerShell 1 10 4 46 C Shell 1 13 7 35 Ruby 2 5 0 32 DOS Batch 11 0 0 31 INI 2 5 0 27 Fortran 77 2 1 1 14 ------------------------------------------------------------------------------- SUM: 4444 266260 433973 1206456 -------------------------------------------------------------------------------
很赞。
再去排除掉iOSAutomation
cloc . --exclude-dir=tool,tmp,task,logging,gameAutomation,debug,data,iOSAutomation
结果:
xxx@xxx ~/dev/xxx/crawler/appAutoCrawler/AppCrawler master ● cloc . --exclude-dir=tool,tmp,task,logging,gameAutomation,debug,data,iOSAutomation 5056 text files. 4518 unique files. 1422 files ignored. github.com/AlDanial/cloc v 1.84 T=28.89 s (131.2 files/s, 54679.6 lines/s) ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- Python 3528 232202 333777 964595 C/C++ Header 108 3036 7638 19675 XSLT 7 609 1108 2347 Cython 21 304 125 2311 C 5 202 149 1638 reStructuredText 17 587 244 1540 CSS 6 8 17 1370 SQL 4 3 0 1129 SVG 2 0 0 934 Markdown 9 299 0 820 PO File 4 161 188 545 JavaScript 6 161 40 380 HTML 7 18 18 326 Fortran 90 15 69 35 252 JSON 20 5 0 212 YAML 1 43 110 101 Protocol Buffers 1 10 0 83 Fish Shell 1 18 15 69 Bourne Shell 10 2 0 48 PowerShell 1 10 4 46 XML 2 0 1 37 C Shell 1 13 7 35 DOS Batch 11 0 0 31 INI 2 5 0 27 Fortran 77 2 1 1 14 ------------------------------------------------------------------------------- SUM: 3791 237766 343477 998565 -------------------------------------------------------------------------------
再去排除掉platformIntegration和venv:
cloc . --exclude-dir=tool,tmp,task,logging,gameAutomation,debug,data,iOSAutomation,platformIntegration,venv
结果:
xxx@xxx ~/dev/xxx/crawler/appAutoCrawler/AppCrawler master ● cloc . --exclude-dir=tool,tmp,task,logging,gameAutomation,debug,data,iOSAutomation,platformIntegration,venv 71 text files. 71 unique files. 6 files ignored. github.com/AlDanial/cloc v 1.84 T=0.45 s (149.9 files/s, 50298.3 lines/s) ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- Python 51 2301 6704 12364 Markdown 1 190 0 525 JSON 3 5 0 113 YAML 1 43 110 101 DOS Batch 10 0 0 30 JavaScript 1 0 0 3 ------------------------------------------------------------------------------- SUM: 67 2539 6814 13136 -------------------------------------------------------------------------------
转载请注明:在路上 » 【已解决】Mac中如何统计指定文件夹下的所有文件的代码行数