linux

Find files by type and count the number of lines they contain

The following command can be used to find all files of a certain type and count the number of lines they contain. This is useful if you want to see how many lines of code a project contains.

First, you'll need to cd to your project directory.

example: Count the number of lines in all JavaScript files.

$ find . -name '*.js' | xargs wc -l
3 ./sandbox/back-to-top-button/js/back-to-top-button.js
6 ./sandbox/tabbed-columns/js/tabbed-column.js
19 ./themes/custom/assets/js/index.js
28 total

The numbers on the left represent the number of lines containing in the file to the right. At the bottom, the number of lines are summed up for all files.

more bash posts

more Linux posts