Last Updated: February 25, 2016
· sendoa

How to measure the number of lines of code in a project

Example for "m" and "h" files. Open your terminal app, go to the folder of your project and type this command:

find . -name "*.[hm]" -print0 | xargs -0 wc -l

Change the ".m" and ".h" extensions to your liking ;-)

For words

find . -name "*.[hm]" -print0 | xargs -0 wc -w

For characters

find . -name "*.[hm]" -print0 | xargs -0 wc -m

Side note

As noted by alhafoudh there is a more elegant way of doing this by using the cloc command. It's not installed by default on OS X though. It can be found here or installed via Homebrew.

2 Responses
Add your response


What about using cloc command?

over 1 year ago ·

Really nice command! Didn't know it. It's not installed on OS X by default though. I installed it through Homebrew and it works like a charm. Pretty cool!

over 1 year ago ·