当前位置:网站首页>Shell script quickly counts the number of lines of project code
Shell script quickly counts the number of lines of project code
2022-07-07 01:46:00 【Li Li】
List of articles
demand
Recently, I suddenly want to see how many lines of code there are in the project under development , But the project is relatively large , It's too troublesome to calculate manually . I think of it. shell Script , Just give it a path , Wait for the statistical results of the script .
Realize the idea
1、 Get all the files in the given path
2、 Determine whether the file is a directory or an ordinary file , If it's a catalog , Continue traversing ; If it's a regular document , next step
3、 Determine file type , Judge according to the file suffix , Such as c++ The suffixes of the source code are .h and .cpp
4、 Calculate the number of matching file lines , Add it up
demo
#!/bin/bash
# Define global variables , Calculate the total number
line=0
# function listFiles: Get the total number of source lines under the specified path
# $1 The full path
# $2 Separator , Used to display the indenting effect of multi-level directories
function listFiles()
{
echo "path:$1"
for file in $(ls $1)
do
# If it is a folder, continue to traverse
if [ -d $file ]; then
echo "$file is dir"
listFiles $1/$file " $2"
else
# It can be modified here as java、py Wait for the file suffix you want to count
if [ ${file##*.} == "h" -o ${file##*.} == "cpp" ];then
echo " $2" "$1/$file line:$(wc -l $1/$file | awk '{print $1}')"
# Add up
let line+=$(wc -l $1/$file | awk '{print $1}')
echo "current line:$line"
fi
fi
done
}
listFiles $1 ""
echo "total line:$line"
effect

The verification results 
It can be seen that ,shell Scripted .h and .cpp The number of lines in the file is correct . You can modify the file suffix to count the number of different source lines ,coding The fun of is also here , Haha, calculate how big the source code of the project is ~
边栏推荐
- 域分析工具BloodHound的使用说明
- 【信号与系统】
- Clickhouse fields are grouped and aggregated, and SQL is queried according to the granularity of any time period
- Box stretch and pull (left-right mode)
- Telnet,SSH1,SSH2,Telnet/SSL,Rlogin,Serial,TAPI,RAW
- Start from the bottom structure to learn the customization and testing of fpga---- FIFO IP
- AcWing 1140. Shortest network (minimum spanning tree)
- 公钥\私人 ssh避password登陆
- JS how to quickly create an array with length n
- JS es5 peut également créer des constantes?
猜你喜欢

今日问题-2022/7/4 lambda体中修改String引用类型变量

AcWing 345. 牛站 题解(floyd的性质、倍增)

百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (下)

设置Wordpress伪静态连接(无宝塔)

Appium自动化测试基础 — uiautomatorviewer定位工具

AcWing 361. 观光奶牛 题解(spfa求正环)
![[advanced C language] 8 written questions of pointer](/img/d4/c9bb2c8c9fd8f54a36e463e3eb2fe0.png)
[advanced C language] 8 written questions of pointer

Appium基础 — Appium Inspector定位工具(一)

修改px4飞控的系统时间

刨析《C语言》【进阶】付费知识【完结】
随机推荐
Match VIM from zero (0) -- Introduction to vimscript
swiper组件中使用video导致全屏错位
AcWing 344. 观光之旅题解(floyd求无向图的最小环问题)
AcWing 346. Solution to the problem of water splashing festival in the corridor (deduction formula, minimum spanning tree)
Today's question -2022/7/4 modify string reference type variables in lambda body
Telnet,SSH1,SSH2,Telnet/SSL,Rlogin,Serial,TAPI,RAW
Baidu flying general BMN timing action positioning framework | data preparation and training guide (Part 1)
制作带照明的DIY焊接排烟器
C语言实例_5
刨析《C语言》【进阶】付费知识【二】
grep查找进程时,忽略grep进程本身
Analyze "C language" [advanced] paid knowledge [End]
Yiwen takes you into [memory leak]
New job insights ~ leave the old and welcome the new~
WCF Foundation
Dark horse notes - create immutable sets and streams
Google发布安全更新,修复Chrome中已被利用的0 day
数据手册中的词汇
黑马笔记---创建不可变集合与Stream流
Can't you understand the code of linked list in C language? An article allows you to grasp the secondary pointer and deeply understand the various forms of parameter passing in the function parameter