ubuntu环境下cloc命令使用

ubuntu环境下使用cloc命令查看代码量

本篇文章以ubuntu系统为例进行操作演示

安装

本人的ubuntu系统是第一次使用cloc命令,所以先来安装下这个工具

sudo apt-get install cloc

安装过程如下

Reading package lists... Done
Building dependency tree
Reading state information... Done
... ...
0 upgraded, 16 newly installed, 0 to remove and 78 not upgraded.
Need to get 533 kB of archives.
After this operation, 1914 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 libclass-method-modifiers-perl all 2.13-1 [16.2 kB]
... ...
Processing triggers for man-db (2.9.1-1) ...

使用

安装完成,先小试牛刀

root@localhost:~/code# cloc ./
      39 text files.
      39 unique files.
       4 files ignored.

github.com/AlDanial/cloc v 1.82  T=0.06 s (652.3 files/s, 90545.1 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Go                              31            379            332           3128
YAML                             4              3              0           1153
Markdown                         1              1              0              1
-------------------------------------------------------------------------------
SUM:                            36            383            332           4282
-------------------------------------------------------------------------------

根据表格可以看到,该工程下的文件个数和不同编程语言的代码行数。

上面命令统计的是当前文件夹下的文件数量和代码数量,但是如果我想统计不同维度的文件代码量呢?

比如只统计指定文件夹下的代码数量

root@localhost:~/code# cloc services/ router/
      15 text files.
      15 unique files.
       0 files ignored.

github.com/AlDanial/cloc v 1.82  T=0.06 s (263.9 files/s, 51505.4 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Go                              12            189            189           1502
YAML                             3              3              0           1044
-------------------------------------------------------------------------------
SUM:                            15            192            189           2546
-------------------------------------------------------------------------------

以及统计排除某些文件夹后的代码量

root@localhost:~/code# cloc ./ --exclude-dir=common
      24 text files.
      24 unique files.
       4 files ignored.

github.com/AlDanial/cloc v 1.82  T=0.05 s (454.4 files/s, 69348.3 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Go                              17            218            208           1730
YAML                             3              3              0           1044
Markdown                         1              1              0              1
-------------------------------------------------------------------------------
SUM:                            21            222            208           2775
-------------------------------------------------------------------------------

其中--exclude-dir表示选项要排除一些文件夹,如果要排除多个文件夹,命令可以写为cloc ./ --exclude-dir=dirA, dirB, 以逗号隔开文件夹名称。

cloc命令可选选项

cloc命令共有五大类的选项,包括Input、Processing、Filter、Debug、Output

   --by-file                 以文件的维度统计代码行数.
   --by-file-by-lang         从文件和编程语言两个维度统计代码行数.
   --count-and-diff <set1> <set2> 首先分别直接统计set1和set2源文件的代码数,然后计算两者的代码差.
   --diff <set1> <set2>      计算set1和set2源文件之间的代码差异,输入可以是文件和目录的混合.
   --git                     如果它们最初未被识别为文件或目录名称,强制输入为git目标.
   --exclude-dir=<D1>[,D2,]  统计除D1,D2文件夹之外的代码量.
   --exclude-ext=<ext1>[,<ext2>[...]]  统计除ext1, ext2等文件扩展名之外的代码量.
   --exclude-lang=<L1>[,L2[...]] 统计除L1,L2,L3编程语言之外的代码量.

如果同学们有其他需求,可以通过cloc --help查看可配置的选项。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值