当前位置:网站首页>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 ~
边栏推荐
- shell脚本快速统计项目代码行数
- C language instance_ four
- Transplant DAC chip mcp4725 to nuc980
- Yunna | work order management software, work order management software app
- Google released a security update to fix 0 days that have been used in chrome
- Make Jar, Not War
- AcWing 1141. LAN problem solving (kruskalkruskal finding the minimum spanning tree)
- 各种语言,软件,系统的国内镜像,收藏这一个仓库就够了: Thanks-Mirror
- tansig和logsig的差异,为什么BP喜欢用tansig
- Start from the bottom structure to learn the customization and testing of fpga---- FIFO IP
猜你喜欢
JS how to quickly create an array with length n
Dark horse notes - exception handling
1123. 最深叶节点的最近公共祖先
刨析《C语言》【进阶】付费知识【完结】
LeetCode:1175. 质数排列
454 Baidu Mianjing 1
C语言关于链表的代码看不懂?一篇文章让你拿捏二级指针并深入理解函数参数列表中传参的多种形式
AI 从代码中自动生成注释文档
Mongodb checks whether the table is imported successfully
Yunna | work order management measures, how to carry out work order management
随机推荐
交叉验证如何防止过拟合
What does security capability mean? What are the protection capabilities of different levels of ISO?
AcWing 345. 牛站 题解(floyd的性质、倍增)
C语言实例_5
Comparison of picture beds of free white whoring
golang 基础 —— 数据类型
mysqlbackup 还原特定的表
LeetCode:1175. 质数排列
搭建【Redis in CentOS7.x】
Box stretch and pull (left-right mode)
[signal and system]
Public key \ private SSH avoid password login
JS es5 peut également créer des constantes?
百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (上)
Blue Bridge Cup 2022 13th provincial competition real topic - block painting
AcWing 1148. Secret milk transportation problem solution (minimum spanning tree)
我如何编码8个小时而不会感到疲倦。
C语言关于链表的代码看不懂?一篇文章让你拿捏二级指针并深入理解函数参数列表中传参的多种形式
长按按钮执行函数
AI automatically generates annotation documents from code