BASH howto – find files with required text in an svn managed folder

This is just a bash (linux/mac terminal) one-liner to look for files with matching text in my rails app, which i do all the time.  It’s a lot faster and more useful than Nautilus’ file search, and is useful when you don’t use any IDEs.  Personally i do everything in the command line and gedit, nice and simple.

Here i’m looking for the string “ratings” in my views folder and my public/javascripts folder

This is broken down as follows:

get all files in these folders
| surround them with quotes (otherwise filenames with spaces would screw up the later steps)
| only consider non-svn files (i’m not interested in the files svn uses to manage things)
| look inside the files for the search string

And here it is:

find app/views public/javascripts -print | awk ‘{print “\””$0″\””}’ | grep -v \.svn | xargs grep -i “ratings”

Obviously this is a bit of a mouthful but once it’s been done it will go into your command memory, and you can get it back by pressing ctrl&r, and starting to type ‘find’.  You may need to press ctrl&r a few more times to get the right command from memory.

Note – wordpress or your browser may change some of the above double quotes to weird web quote characters.  I really fracking hate that.  Anyway, when you paste it over, change all the quotes to normal single or double quotes.


Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s