Gurmeet Singh
Gurmeet Singh

Reputation: 51

Grep command- How to use in different directories

How to grep single word in different directory and file name is also same in different directory.

Upvotes: 5

Views: 8325

Answers (3)

knittl
knittl

Reputation: 265271

If you are using bash you can use the following:

grep 'pattern' {dir1,dir2,dir3}/filename

Upvotes: 4

Oswald
Oswald

Reputation: 31655

Specify each file as an argument:

grep -w vwhat /some/file /another/file /a/third/file

Upvotes: 2

I'm not sure to understand what you want.

Can't you just run

  grep -rwn word /some/dir1/ /other/dir2/

Read the GNU grep documentation!

Upvotes: 7

Related Questions