当前位置:网站首页>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 ~
边栏推荐
- AcWing 1148. 秘密的牛奶运输 题解(最小生成树)
- Transplant DAC chip mcp4725 to nuc980
- 刨析《C语言》【进阶】付费知识【完结】
- AcWing 346. Solution to the problem of water splashing festival in the corridor (deduction formula, minimum spanning tree)
- 【C语言进阶篇】指针的8道笔试题
- Dark horse notes - create immutable sets and streams
- ZOJ Problem Set – 2563 Long Dominoes 【如压力dp】
- C语言实例_2
- AcWing 1141. LAN problem solving (kruskalkruskal finding the minimum spanning tree)
- 黑马笔记---异常处理
猜你喜欢
设置Wordpress伪静态连接(无宝塔)
Yunna - work order management system and process, work order management specification
JVM 内存模型
AI 从代码中自动生成注释文档
shell脚本快速统计项目代码行数
Yunna | work order management software, work order management software app
Dark horse notes - create immutable sets and streams
Today's question -2022/7/4 modify string reference type variables in lambda body
AcWing 361. 观光奶牛 题解(spfa求正环)
对C语言数组的再认识
随机推荐
json学习初体验–第三者jar包实现bean、List、map创json格式
Make Jar, Not War
Public key \ private SSH avoid password login
字符串的相关编程题
AcWing 1141. 局域网 题解(kruskalkruskal 求最小生成树)
AcWing 344. 观光之旅题解(floyd求无向图的最小环问题)
一起看看matlab工具箱内部是如何实现BP神经网络的
Amway wave C2 tools
AcWing 346. 走廊泼水节 题解(推公式、最小生成树)
[chip scheme design] pulse oximeter
First experience of JSON learning - the third-party jar package realizes bean, list and map to create JSON format
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
HDU 4661 message passing (wood DP & amp; Combinatorics)
Basic introduction and use of dvajs
When grep looks for a process, it ignores the grep process itself
LeetCode:1175. 质数排列
POJ 3177 redundant paths POJ 3352 road construction (dual connection)
Drag to change order
JS ES5也可以创建常量?
【芯片方案设计】脉搏血氧仪