计算项目中不包括某些文件夹或文件的总行数
使用命令:
wc -l + `find . -name \* -print`
可以获得文件夹内所有文件的总行数。
但是想象一下您有一些文件夹(例如库),您不想计算它们的行数,因为您没有编写它们。
那么,如何计算项目中排除某些文件夹的行数呢?
Using the command:
wc -l + `find . -name \* -print`
You can get the total number of lines of all files inside a folder.
But imagine you have some folders (for example libraries), which you don't want to count their lines because you didn't write them.
So, how would you count the lines in a project excluding certain folders?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
每当我需要计算源代码行数时, cloc 一直是我的好朋友。以2.6.29 linux内核为例:
cloc has always been a great friend whenever I need to count lines of src-code. Using 2.6.29 linux kernel as an example:
使用
find
,您还可以使用!
“否定”匹配条件。例如,如果我想列出目录中的所有.java
文件,不包括包含Test
的文件:find 。 -名称“*.java”! -name "*Test*"
希望这有帮助!
编辑:
顺便说一句,
-name
谓词仅过滤文件名。如果您想过滤路径(以便可以过滤目录),请使用-path
:find 。 -路径“*.java”! -路径“*测试*”
With
find
, you can also "negate" matching conditions with!
. For example, if I want to list all the.java
files in a directory, excluding those containingTest
:find . -name "*.java" ! -name "*Test*"
Hope this helps!
Edit:
By the way, the
-name
predicate only filters file names. If you want to filter paths (so you can filter directories), use-path
:find . -path "*.java" ! -path "*Test*"
您始终可以通过使用正则表达式列出文件来排除它们,
例如,
*.txt 将仅包含 txt 文件等等...
you could always exclude them by listing out the files using regular expressions,
for example,
*.txt will include only txt files and so on...
我专门为此用途制作了一个 NPM 包,它允许您调用 CLI 工具并提供目录路径和文件夹/文件以忽略
它,如下所示:
npm i -g @quasimodo147/countlines
到在终端中输入
$ countlines
命令即可
计数线。 node_modules构建分布
I made an NPM package specifically for this usage, which allows you to call a CLI tool and providing the directory path and the folders/files to ignore
it goes like:
npm i -g @quasimodo147/countlines
to get the
$ countlines
command in your terminalthen you can do
countlines . node_modules build dist