/ Tool

查看代码行数-代码规模统计

前言

分享一个小工具 , 可以用来查看到你项目中的代码数量 , 满足一些童鞋的好奇心 , 当然在做项目汇报的时候也可以有所帮助.

介绍

CLOC (Count Line of Code)

点击名称即可下载

输出效果 (以我的项目为例):

        2020 text files.
        1761 unique files.                                          
         530 files ignored.
     
    http://cloc.sourceforge.net v 1.64  T=10.74 s (138.9 files/s, 20711.8 lines/s)
    -------------------------------------------------------------------------------
    Language                     files          blank        comment           code
    -------------------------------------------------------------------------------
    Objective C                    626          56238          15635          94476
    C/C++ Header                   730          12683          19977          14469
    Objective C++                   17            827            302           3682
    JSON                           112              0              0           2464
    C++                              1            164            156            754
    Swift                            1             36             30            322
    Bourne Shell                     2             22             10            185
    HTML                             2             11              0             98
    Javascript                       1              0              1              4
    -------------------------------------------------------------------------------
    SUM:                          1492          69981          36111         116454
    -------------------------------------------------------------------------------

CLOC支持的文件格式:

ABAP                       (abap)
ActionScript               (as)
Ada                        (ada, adb, ads, pad)
ADSO/IDSM                  (adso)
AMPLE                      (ample, dofile, startup)
Ant                        (build.xml)
Apex Trigger               (trigger)
Arduino Sketch             (ino, pde)
ASP                        (asa, asp)
ASP.Net                    (asax, ascx, asmx, aspx, config, master, sitemap, webinfo)
Assembly                   (asm, S, s)
AutoHotkey                 (ahk)
awk                        (awk)
Bourne Again Shell         (bash)
Bourne Shell               (sh)
C                          (c, ec, pgc)
C Shell                    (csh, tcsh)
C#                         (cs)
C++                        (C, c++, cc, cpp, cxx, pcc)
C/C++ Header               (H, h, hh, hpp)
CCS                        (ccs)
Clojure                    (clj)
ClojureScript              (cljs)
CMake                      (cmake, CMakeLists.txt)
COBOL                      (CBL, cbl, cob, COB)
CoffeeScript               (coffee)
ColdFusion                 (cfm)
ColdFusion CFScript        (cfc)
CSS                        (css)
CUDA                       (cu)
Cython                     (pyx)
D                          (d)
DAL                        (da)
Dart                       (dart)
DOS Batch                  (bat, BAT, btm, BTM, cmd, CMD)
DTD                        (dtd)
ECPP                       (ecpp)
Erlang                     (erl, hrl)
Expect                     (exp)
F#                         (fs, fsi)
Focus                      (focexec)
Fortran 77                 (F, f, F77, f77, pfo)
Fortran 90                 (F90, f90)
Fortran 95                 (F95, f95)
Go                         (go)
Grails                     (gsp)
Groovy                     (gant, groovy)
Haml                       (haml)
Handlebars                 (handlebars, hbs)
Harbour                    (hb)
Haskell                    (hs, lhs)
HLSL                       (cg, cginc, shader)
HTML                       (htm, html)
IDL                        (idl, pro)
InstallShield              (ism)
Java                       (java)
Javascript                 (js)
JavaServer Faces           (jsf, xhtml)
JCL                        (jcl)
JSON                       (json)
JSP                        (jsp, jspf)
Kermit                     (ksc)
Korn Shell                 (ksh)
Kotlin                     (kt)
LESS                       (less)
lex                        (l)
Lisp                       (el, jl, lisp, lsp, sc)
Lisp/OpenCL                (cl)
LiveLink OScript           (oscript)
Lua                        (lua)
m4                         (ac, m4)
make                       (am, gnumakefile, Gnumakefile, Makefile, makefile)
MATLAB                     (m)
Maven                      (pom, pom.xml)
Modula3                    (i3, ig, m3, mg)
MSBuild script             (csproj, vbproj, vcproj, wdproj, wixproj)
MUMPS                      (mps, m)
Mustache                   (mustache)
MXML                       (mxml)
NAnt script                (build)
NASTRAN DMAP               (dmap)
Objective C                (m)
Objective C++              (mm)
OCaml                      (ml, mli, mll, mly)
Oracle Forms               (fmt)
Oracle Reports             (rex)
Pascal                     (dpr, p, pas)
Pascal/Puppet              (pp)
Patran Command Language    (pcl, ses)
Perl                       (perl, PL, pl, plh, plx, pm)
PHP                        (php, php3, php4, php5)
PHP/Pascal                 (inc)
Pig Latin                  (pig)
PL/I                       (pl1)
PowerShell                 (ps1)
Python                     (py)
QML                        (qml)
R                          (R)
Racket                     (rkt, rktl, sch, scm, scrbl, ss)
Razor                      (cshtml)
Rexx                       (rexx)
RobotFramework             (tsv)
Ruby                       (rake, rb)
Ruby HTML                  (rhtml)
Rust                       (rs)
SASS                       (sass, scss)
Scala                      (scala)
sed                        (sed)
SKILL                      (il)
SKILL++                    (ils)
Smarty                     (smarty, tpl)
Softbridge Basic           (sbl, SBL)
SQL                        (psql, sql, SQL)
SQL Data                   (data.sql)
SQL Stored Procedure       (spc.sql, spoc.sql, sproc.sql, udf.sql)
Swift                      (swift)
Tcl/Tk                     (itk, tcl, tk)
Teamcenter met             (met)
Teamcenter mth             (mth)
TypeScript                 (ts)
Unity-Prefab               (mat, prefab)
Vala                       (vala)
Vala Header                (vapi)
Velocity Template Language (vm)
Verilog-SystemVerilog      (sv, svh, v)
VHDL                       (vhd, VHD, VHDL, vhdl)
vim script                 (vim)
Visual Basic               (bas, cls, ctl, dsr, frm, vb, VB, vba, VBA, vbs, VBS)
Visualforce Component      (component)
Visualforce Page           (page)
Windows Message File       (mc)
Windows Module Definition  (def)
Windows Resource File      (rc, rc2)
WiX include                (wxi)
WiX source                 (wxs)
WiX string localization    (wxl)
XAML                       (xaml)
xBase                      (prg)
xBase Header               (ch)
XML                        (XML, xml)
XQuery                     (xq, xquery)
XSD                        (xsd, XSD)
XSLT                       (xsl, XSL, xslt, XSLT)
yacc                       (y)
YAML                       (yaml, yml)

使用

首先下载cloc.pl 只有一个perl文件 , 下载后就可以直接使用了.

下载好后你会得到这样一个东东 , 不要在意名字 , cloc -版本号.pl

cloc.pl

下面打开终端 , cd 到这个文件的目录 , 输入以下命令就可以查看到你的代码信息了:

perl cloc-对应的版本号.pl 你要查询的工程路径

举个例子:

perl cloc-1.64.pl /Users/LEE/Desktop/LEEAlert

执行命令后 就可以看到你想要的结果了.

执行结果

内容我就不一一介绍了 大家都看得懂.

执行下面命令可以查看CLOC所有支持的语言:

perl cloc-1.64.pl --show-lang

执行结果上面也有介绍的 , 常用的使用方法就介绍到这里 , 更多的使用方法可以到官网里面找.