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

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

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay