DEV Community

Cover image for CLI Command that finds all files of a certain type and ignores Node_Modules
Gedalya Krycer
Gedalya Krycer

Posted on • Edited on

CLI Command that finds all files of a certain type and ignores Node_Modules

Overview

Learned this cool little terminal searching trick that prints a list of all the files of a certain type there are in a project directory. In addition, it will show how many lines of code each file has and will exclude looking in specified directories.

This can be very helpful when viewing a code base for the first time and you want to see how much JavaScript there is.


Full Command

$ find . -path ./node_modules -prune -o -name '*.js' | xargs wc -l

Breakdown

$ find . {...} -name '*.js' {...}

  • This block finds all the files that match ‘.js’. the file name extension can of course be updated to match a different file type.

$ {...} -path ./node_modules -prune -o {...}

  • This block excludes the node_modules folder. (Or any other directory specified.)

$ {...} | xargs wc -l

  • This block tells the terminal to also include how many lines of code each file has and a sum of all the lines at the end of the report.

Credit

I learned about this trick by viewing Nick Janetakis's tutorial on Learning a New and Unfamiliar Code Base and this Stack Overflow article

Top comments (0)