linux系统中简单统计python项目代码行数信息
python项目行数统计#!/bin/bash # 忽略该目录下的文件和忽略某些后缀文件注意下面的-not -path和-not -name find . -type f \ -not -path */node_modules/* \ -not -path */dist/* \ -not -path */build/* \ -not -path */out/* \ -not -path */target/* \ -not -path */.git/* \ -not -path */.svn/* \ -not -path */.idea/* \ -not -path */.vscode/* \ -not -path */venv/* \ -not -path */.venv/* \ -not -path */__pycache__/* \ -not -path */vendor/* \ -not -path */log/* \ -not -path */logs/* \ -not -path */test/* \ -not -path */tests/* \ -not -name *.log \ -not -name *.sql \ -not -name *.bak \ -not -name *.old \ -not -name *.tmp \ # 统计以下文件 \( -name *.py -o -name *.pyi -o -name *.yml -o -name *.yaml -o -name *.toml -o -name *.ini \) \ -print0 | xargs -0 cat 2/dev/null | awk BEGIN { total 0 empty 0 comment 0 code 0 } { total orig $0 trimmed orig gsub(/^[[:space:]]|[[:space:]]$/, , trimmed) if (trimmed ) { empty next } s orig gsub(/[^]*/, , s) gsub(/[^]*/, , s) gsub(/([^\\]|\\.)*/, , s) gsub(/([^\\]|\\.)*/, , s) gsub(/#.*/, , s) gsub(/^[[:space:]]|[[:space:]]$/, , s) if (s ) comment else code } END { print print Python 项目【纯净业务代码】 print 总行数: total print 空行数: empty print 注释行数: comment print 有效代码行: code printf(注释率: %.2f%%\n, total0 ? comment/total*100 : 0) print }使用方法和java一样见linux系统中简单统计java项目代码行数信息