arguments.callee web design & development blog  


Recursive Find-in-Files on Linux or Unix

I find myself needing this more and more often lately, so I figured this is as good a place as any to keep track of it. Here's how to recursively search for files containing a particular string or regular expression. This should work on most Linux or UNIX systems, depending on your configuration.

    find -type f -name "*" | xargs grep 'word, phrase, or regular expression'

Summary for the curious:

  • find returns the names of one or more files, but not their contents.
  • -type f tells find to only look at files, not directories.
  • -name "*" tells find to examine everything. You can replace this with "*.js" to only search JavaScript files, for example.
  • | "pipes" the output of the command on the left to the input of the command on the right.
  • xargs creates and executes a command based on the arguments you pass to it.
  • grep searches the contents of files and returns each line that is a match.
  • '...' is a regular expression (or just a word, if you prefer) that indicates what you are searching for.
Tags




blog comments powered by Disqus
search blog
  • Programming-Collective-Intelligence-Building-Applications
  • jQuery-Cookbook-Solutions-Examples-Developers
categories & tags
random posts
about hb stone

I'm a Front-End Engineer at Yahoo! working on the Mail and Messenger teams. I blog about web design and development topics including accessibility, usability, performance, and developing HTML / CSS / JavaScript applications on Appcelerator Titanium and Adobe AIR.

If you're a web developer, you might enjoy Jelo, my JavaScript library.

  • Information-Dashboard-Design-Effective-Communication
  • Flash-Catalyst-CS5-Bible-Huddleston
copyright

All original work on this site is covered by a Creative Commons Attribution 3.0 license unless otherwise specified.

You may share or use any code or images from this site in any manner, for free, so long as reasonable effort has been made to give credit where due.

The views expressed in the posts and comments on this blog do not necessarily reflect the views of Yahoo!