Search your server with Grep

Search your server with Grep

This is a short tip, but it piggy backs off my two previous posts to get you guys out of the guise of desktop tools and into the terminal!

Haven’t you ever wanted to do a ‘Ctrl-F’ type search on your web files? Wouldn’t it be cool if you could just find in your web server all the instances of an email address so you could update it across files?

Never fear, grep is here.

Grep is a Unix-based utility that does a simple text search on files that you specify. It then returns to the screen where that text is and where it is used. It works just like the search you’re use to in Windows, except for your files on a particular server.

As alluded to before, this is especially useful if you’re trying to comment out or change text on a website, but you’re not sure how often the text is repeated or in what files it appears!

For example, let’s say my boss asked me to update the email address that is listed on our 100-page website anywhere it’s listed. When I log into the terminal (see my SSH posts, again, for instructions on how to do that), I can simply type:

> grep -l 'example@email.com' *

Breaking that down, the ‘grep’ command invokes the tool, the ‘-l’ (dash lowercase L) says to list only the filenames, the ‘example@email.com’ (quotes included because I am using the @ symbol) dictates the text to look for, and the ‘*’ dictates to look in all the files in my current directory. What outputs is a nice list of files to manipulate!

Bonus Tip: Check out grep for Windows!

Category: Jargon, web 2.0 | Tags: ,
About the Author
Fredric is a professional web developer specializing in Drupal and PHP over at brightplum.com. Although his affinity for all things interweb borderlines on unhealthy, his wife assures him that his son will grow up just as much of a tech nerd as he is. You can also find him giving back and blogging over at ybpguide.com.
See all posts by .

Related Posts

advertisement

Comments

advertisement





Like & Follow Us





NewME Community

advertisement