Skip to content

Instantly share code, notes, and snippets.

@gallir
Created February 2, 2015 19:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gallir/4b88005310587b056ca4 to your computer and use it in GitHub Desktop.
Save gallir/4b88005310587b056ca4 to your computer and use it in GitHub Desktop.
Seach a word recursively in all files under the current working direcrtory
#! /usr/bin/env bash
if [ $# -eq 0 ]
then
echo "No word supplied"
fi
word=$1
find . -type f -and -not -path '*/.git/*' -and -not -path '*/.svn/*' -exec grep -i -H "$word" {} \;
@gallir
Copy link
Author

gallir commented Feb 2, 2015

Copy the file to a directory in your path, for example: references
chmod +x references

Usage:
references word_to_search

Example:

gallir@darwin:/tmp/linux-3.18.5$ references spin_unlock
./block/bio.c: spin_unlock(&bs->rescue_lock);
./block/bio.c: spin_unlock(&bs->rescue_lock);
./block/bio.c: spin_unlock_irqrestore(&bio_dirty_lock, flags);
./block/bio.c: spin_unlock_irqrestore(&bio_dirty_lock, flags);
./block/blk-cgroup.c: spin_unlock(&blkcg->lock);
....

PS: You can do it with grep -R... but I'm an old fan of find ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment