当前位置:网站首页>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 ~
边栏推荐
- 454 Baidu Mianjing 1
- POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)
- Yunna | work order management measures, how to carry out work order management
- Set WordPress pseudo static connection (no pagoda)
- 搭建【Redis in CentOS7.x】
- 7.6 simulation summary
- json学习初体验–第三者jar包实现bean、List、map创json格式
- Yiwen takes you into [memory leak]
- New job insights ~ leave the old and welcome the new~
- 鼠标右键 自定义
猜你喜欢
Mongodb checks whether the table is imported successfully
百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (下)
1123. 最深叶节点的最近公共祖先
Today's question -2022/7/4 modify string reference type variables in lambda body
设置Wordpress伪静态连接(无宝塔)
The cradle of eternity
场景实践:基于函数计算快速搭建Wordpress博客系统
Yunna - work order management system and process, work order management specification
蓝桥杯2022年第十三届省赛真题-积木画
JS reverse -- ob confusion and accelerated music that poked the [hornet's nest]
随机推荐
C language instance_ five
Appium automation test foundation uiautomatorviewer positioning tool
糊涂工具类(hutool)post请求设置body参数为json数据
剑指 Offer II 035. 最小时间差-快速排序加数据转换
C语言实例_2
shell脚本快速统计项目代码行数
What does security capability mean? What are the protection capabilities of different levels of ISO?
MySQL最基本的SELECT(查询)语句
JS Es5 can also create constants?
tansig和logsig的差异,为什么BP喜欢用tansig
JS reverse -- ob confusion and accelerated music that poked the [hornet's nest]
永久的摇篮
Box stretch and pull (left-right mode)
场景实践:基于函数计算快速搭建Wordpress博客系统
Sword finger offer II 035 Minimum time difference - quick sort plus data conversion
LeetCode:1175. 质数排列
Comparison of picture beds of free white whoring
Reptile practice (VI): novel of climbing pen interesting Pavilion
Instructions for using the domain analysis tool bloodhound
Gin introduction practice