Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6088855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:02:02+00:00 2026-05-23T12:02:02+00:00

I want to traverse all subdirectories, except the node_modules directory.

  • 0

I want to traverse all subdirectories, except the node_modules directory.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:02:03+00:00Added an answer on May 23, 2026 at 12:02 pm

    SOLUTION 1 (combine find and grep)

    The purpose of this solution is not to deal with grep performance but to show a portable solution : should also work with busybox or GNU version older than 2.5.

    Use find, for excluding directories foo and bar :

    find /dir \( -name foo -prune \) -o \( -name bar -prune \) -o -name "*.sh" -print
    

    Then combine find and the non-recursive use of grep, as a portable solution :

    find /dir \( -name node_modules -prune \) -o -name "*.sh" -exec grep --color -Hn "your text to find" {} 2>/dev/null \;
    

    SOLUTION 2 (using the --exclude-dir option of grep):

    You know this solution already, but I add it since it’s the most recent and efficient solution. Note this is a less portable solution but more human-readable.

    grep -R --exclude-dir=node_modules 'some pattern' /path/to/search
    

    To exclude multiple directories, use --exclude-dir as:

    --exclude-dir={node_modules,dir1,dir2,dir3}

    SOLUTION 3 (Ag)

    If you frequently search through code, Ag (The Silver Searcher) is a much faster alternative to grep, that’s customized for searching code. For instance, it automatically ignores files and directories listed in .gitignore, so you don’t have to keep passing the same cumbersome exclude options to grep or find.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to traverse all sub-folders of a particular folder and check whether they
I am trying to traverse all directories under the current directory using a shell
So I am trying to traverse a directory and find all the instances of
I want to traverse all the children in some container (Grid, Canvas etc) in
I want to traverse all nodes with all outgoing relationships. But all examples I
I want to traverse through all the elements of an word document one by
i want to write a page that will traverse a specified directory.... and get
i am currently implementing a binary tree in c++ and i want to traverse
I want to override the selection behavior of ListBox Items. We can traverse through
I wrote a small program that uses Mechanize to traverse a site. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.