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

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

Enjoy the article? Join over 17,500+ Swift developers and enthusiasts who get my weekly updates.

  • 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