Linux Command Line Trick: Find All Files With A Specific Word Inside

19 Jun

Still learning command line tricks! Here is a great CLI cheatsheet to reference.

To find a file witha  specific keyword in it, simply enter the following into your command line:

  $ grep -r "keyword" * 

Here is a more comprehensive example if you want to test this out:

# clone this directory (or do this within whichever directory you're working with)

$ git clone https://github.com/sharksforcheap/CLI-Obstacle-Course

# go into the new CLI-Obstacle-Course directory

$ cd CLI-Obstacle-Course

# find all files with the method name "bootinator" in it
$ grep -r "bootinator" *

#result
app/assets/stylesheets/application_helper.rb: def bootinator(name)
app/views/animals/new.html.erb:
Then the distressed file said

app/views/cars/new.html.erb:
Then the distressed file said

app/views/people/new.html.erb:
Then the distressed file said

app/views/schools/new.html.erb:
Then the distressed file said

app/views/static_pages/new.html.erb:
Then the distressed file said

Advertisements

One Response to “Linux Command Line Trick: Find All Files With A Specific Word Inside”

  1. Khara June 19, 2012 at 4:03 pm #

    Thank you for posting this! I googled to find the answer and your post was listed. DBC is going to have to come up with new exercises ;P

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