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

1

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

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more