Skip to content

Instantly share code, notes, and snippets.

@ahmetb
Created February 17, 2013 22:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmetb/4973807 to your computer and use it in GitHub Desktop.
Save ahmetb/4973807 to your computer and use it in GitHub Desktop.
Quick SLoC counter in CLI
# 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
@ahmetb
Copy link
Author

ahmetb commented Feb 17, 2013

Somebody should create an alias out of this: sloc *.java or sloc *.m, that would be fun!

@cihati
Copy link

cihati commented Feb 19, 2013

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.

@ahmetb
Copy link
Author

ahmetb commented Mar 13, 2013

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