Linux教程

Linux代码行数统计

本文主要是介绍Linux代码行数统计,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1.事例文件

$ tree
.
├── cnt1.c
├── cnt1.h
├── cnt2.c
├── cnt3.c
└── sub
    ├── cnt4.c
    ├── cnt5.c
    └── cnt6.py

2.基于findwc的方式

# print 方式
$ find . "(" -name "*.c" -or -name "*.h" ")" -print | xargs wc -l  
0  ./cnt1.h 
11 ./cnt2.c 
11 ./sub/cnt4.c 
11 ./sub/cnt5.c 
11 ./cnt3.c 
11 ./cnt1.c 
55 total
# cat 方式
$ find -name "*.c" -o -name "*.h" |xargs cat|wc -l
533706

3.基于cloc方式

$  cloc ./
7 text files.       2 unique files.       5 files ignored.github.com/AlDanial/cloc v 1.82  T=0.01 s (357.2 files/s, 2321.8 lines/s)-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Python                           1              1              3              8
C/C++ Header                     1              0              0              1
-------------------------------------------------------------------------------
SUM:                             2              1              3              9
-------------------------------------------------------------------------------

cloc似乎可以过滤重复文件,有时间单独学一下使用方法

这篇关于Linux代码行数统计的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!