Quick Recursive Code Count

Although the “lines of code” in a project is not the worlds most useful metric. Curiosity sometimes gets the better of us and after many days / weeks of typing you think “gee I wonder exactly how many lines of code are in that project?”.

Wonder no more! By embracing the power of the command line you can easily count the lines in every file recursively. Simply execute the following line in the directory of your project (changing .php to the file extension of the files you would like to count the line of):

find . -name ‘*.php’ | xargs wc -l

This will give you a simple breakdown for your project that looks similar to below:

59 ./upload-video.php
15 ./views/settings/configuration_required.php
215 ./views/settings/plugin-settings.php
66 ./views/playlist-management/edit-playlist.php
91 ./views/playlist-management/playlist-management.php
57 ./views/playlist-management/reorder-playlist.php
74 ./views/playlist-management/create-playlist.php
60 ./views/video-management/play-playlist.php
117 ./views/video-management/existing-videos.php
59 ./views/video-management/upload-video.php
44 ./views/video-management/play-video.php
25 ./views/video-management/preview-video.php
58 ./includes/shared.php
29 ./includes/reorder_playlist.php
40 ./includes/plugin_setup.php
100 ./includes/playlist_management.php
1921 ./includes/s3.php
40 ./includes/video_tracking.php
371 ./s3-video.php
3441 total

Sure its not the most detailed or elegant report but its quick and gives you a code count of your project with a minimum of fuss.

Leave a Reply

Your email address will not be published. Required fields are marked *