用于计算 Python 或 Bash 中代码行数的实用程序
python 或 bash 脚本中是否有一种快速而肮脏的方法,可以递归地下降目录并计算代码的总行数?不过,我们希望能够排除某些目录。
例如:
start at: /apps/projects/reallycoolapp
exclude: lib/, frameworks/
排除的目录也应该是递归的。例如:
/app/projects/reallycool/lib SHOULD BE EXCLUDED
/app/projects/reallycool/modules/apple/frameworks SHOULD ALSO BE EXCLUDED
这将是一个非常有用的实用程序。
Is there a quick and dirty way in either python or bash script, that can recursively descend a directory and count the total number of lines of code? We would like to be able to exclude certain directories though.
For example:
start at: /apps/projects/reallycoolapp
exclude: lib/, frameworks/
The excluded directories should be recursive as well. For example:
/app/projects/reallycool/lib SHOULD BE EXCLUDED
/app/projects/reallycool/modules/apple/frameworks SHOULD ALSO BE EXCLUDED
This would be a really useful utility.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
发现了一个很棒的实用程序 CLOC。 https://github.com/AlDanial/cloc
这是我们运行的命令:
这是输出
Found an awesome utility CLOC. https://github.com/AlDanial/cloc
Here is the command we ran:
And here is the output
仅
find
和wc
参数就可以解决您的问题。使用
find
您可以指定非常复杂的逻辑,如下所示:这里
!
反转条件,因此该命令将计算不在 'lib/' 或 'lib/' 中的每个 python 文件的行数“框架/”目录。只是不要忘记“*”,否则它不会匹配任何内容。
The
find
andwc
arguments alone can solve your problem.With
find
you can specify very complex logic like this:Here the
!
invert the condition so this command will count the lines for each python files not in 'lib/' or in 'frameworks/' directories.Just dont forget the '*' or it will not match anything.
一些注释
cut
命令如何将计数与文件名分开,A few notes...
cut
command can separate the count from the file namegrep -e .html$ -e .css$