Skip to main content
Please always mention your OS
Source Link
terdon
  • 252.2k
  • 69
  • 480
  • 718

I am searching through a Ruby on Rails application for a word using grepgrep on OSX, and I would like to exclude directories that match a certain pattern.

I am using the following command:

grep -inRw -E 'direct' . --exclude-dir -E 'git|log|asset'

This command is not doing what I thought it would do. Here is how I thought it would work:

  • i - case insensitive search
  • n - print line number in which pattern is found
  • R - search recursively
  • w - I only want whole words - i.e., match "direct" but not "directory"
  • -E - use extended regular expression
  • 'direct' - the regular expression I want to match
  • . - search in the current directory
  • --exclude-dir -E 'git|log|asset' - exclude directories that match git or log or asset.

In terms of the exclude directories, the command still ends up searching in the './git' and './log' directories, as well as in './app/assets'

I'm obviously lacking a fundamental piece of knowledge, but I do not know what it is.

I am searching through a Ruby on Rails application for a word using grep, and I would like to exclude directories that match a certain pattern.

I am using the following command:

grep -inRw -E 'direct' . --exclude-dir -E 'git|log|asset'

This command is not doing what I thought it would do. Here is how I thought it would work:

  • i - case insensitive search
  • n - print line number in which pattern is found
  • R - search recursively
  • w - I only want whole words - i.e., match "direct" but not "directory"
  • -E - use extended regular expression
  • 'direct' - the regular expression I want to match
  • . - search in the current directory
  • --exclude-dir -E 'git|log|asset' - exclude directories that match git or log or asset.

In terms of the exclude directories, the command still ends up searching in the './git' and './log' directories, as well as in './app/assets'

I'm obviously lacking a fundamental piece of knowledge, but I do not know what it is.

I am searching through a Ruby on Rails application for a word using grep on OSX, and I would like to exclude directories that match a certain pattern.

I am using the following command:

grep -inRw -E 'direct' . --exclude-dir -E 'git|log|asset'

This command is not doing what I thought it would do. Here is how I thought it would work:

  • i - case insensitive search
  • n - print line number in which pattern is found
  • R - search recursively
  • w - I only want whole words - i.e., match "direct" but not "directory"
  • -E - use extended regular expression
  • 'direct' - the regular expression I want to match
  • . - search in the current directory
  • --exclude-dir -E 'git|log|asset' - exclude directories that match git or log or asset.

In terms of the exclude directories, the command still ends up searching in the './git' and './log' directories, as well as in './app/assets'

I'm obviously lacking a fundamental piece of knowledge, but I do not know what it is.

edited title
Link
don_crissti
  • 85.6k
  • 31
  • 234
  • 262

Using grep with the --exclude-dir flag to exclude multiple directories

Source Link
Steven L.
  • 785
  • 1
  • 9
  • 10

Using grep with the --exclude-dir flag

I am searching through a Ruby on Rails application for a word using grep, and I would like to exclude directories that match a certain pattern.

I am using the following command:

grep -inRw -E 'direct' . --exclude-dir -E 'git|log|asset'

This command is not doing what I thought it would do. Here is how I thought it would work:

  • i - case insensitive search
  • n - print line number in which pattern is found
  • R - search recursively
  • w - I only want whole words - i.e., match "direct" but not "directory"
  • -E - use extended regular expression
  • 'direct' - the regular expression I want to match
  • . - search in the current directory
  • --exclude-dir -E 'git|log|asset' - exclude directories that match git or log or asset.

In terms of the exclude directories, the command still ends up searching in the './git' and './log' directories, as well as in './app/assets'

I'm obviously lacking a fundamental piece of knowledge, but I do not know what it is.