Linux 统计代码行数的代码
统计文件行数(单个文件):
wc -l file
例如:
homer@ubuntu:~/workspace/android/game$ wc -l lgameandroid2dactivity.java
906 lgameandroid2dactivity.java
统计目录所有文件行数(全部目录):
find . -name *.java | xargs wc -l
例如:
homer@ubuntu:~/workspace/android$ find . -name *.java | xargs wc -l
817 ./game/core/lhandler.java
140 ./game/core/lflicker.java
...
515 ./game/utils/collection/arraymap.java
162 ./game/utils/collisionutils.java
178 ./game/utils/numberutils.java
68753 total
统计目录并按行数排序(按行大小排序):
find . -name *.java | xargs wc -l | sort -n
homer@ubuntu:~/workspace/android$ find . -name *.java | xargs wc -l | sort -n
25 ./game/action/sprite/collidable.java
26 ./game/core/graphics/component/collisionquery.java
27 ./game/core/graphics/filter/imagefilter.java
28 ./game/lmode.java
...
1467 ./game/core/geom/path2d.java
1919 ./game/core/graphics/screen.java
2417 ./game/core/graphics/device/lgraphics.java
3050 ./game/core/geom/affinetransform.java
68753 total
统计目录并按行数排序(按行文件名排序):
find . -name *.java | xargs wc -l | sort -k2
homer@ubuntu:~/workspace/android$ find . -name *.java | xargs wc -l | sort -k2
210 ./game/action/actioncontrol.java
116 ./game/action/actionevent.java
34 ./game/action/actionlistener.java
....
178 ./game/utils/numberutils.java
342 ./game/utils/recordstoreutils.java
58 ./game/utils/screenutils.java
650 ./game/utils/stringutils.java
68753 total