Created
February 17, 2013 22:21
-
-
Save ahmetb/4973807 to your computer and use it in GitHub Desktop.
Quick SLoC counter in CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Counts source lines of code in current directory. Replace *.java with your source extension. | |
# (ignores empty lines) | |
find . -type f -name '*.java' -exec cat {} \; | sed '/^\s*$/d' | wc -l | |
# to ignore comments (in languages where comments start with #) | |
find . -type f -name '*.java' -exec cat {} \; | sed '/^\s*#/d;/^\s*$/d' | wc -l |
In my system (Mac OS X 10.7.5), sed
doesn't recognize \s
as a command, so this doesn't work correctly. Using [ \t]
instead seems to solve the issue.
In most package managers (apt, brew etc) there is sloccount
package. It gives detailed stats, you better use it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Somebody should create an alias out of this:
sloc *.java
orsloc *.m
, that would be fun!