Grepping a directory

Suppose there is a modules_classes/ directory with player.rb and wrapper.rb files. Write a command that finds all lines in the file with the word dog.

$ grep dog modules_classes/wrapper.rb 

Now, let’s search all the files in the modules_classes/ directory for the word dog. This code will not work:

$ grep dog modules_classes/

We need to add a flag to the command so grep knows to perform a recursive search throughout the directory.

$ grep class -R modules_classes/

If we also wanted to perform a case-insensitive search, we would need to add the -i flag:

$ grep class -iR modules_classes/

ack is a wonderful tool for searching source code that programmers also love.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s