Skip to content

Instantly share code, notes, and snippets.

@okomestudio
Last active August 29, 2015 14:04
Show Gist options
  • Save okomestudio/cc3cd23b3824aace571a to your computer and use it in GitHub Desktop.
Save okomestudio/cc3cd23b3824aace571a to your computer and use it in GitHub Desktop.
Search for files containing a specified string.
#!/bin/bash
##############################################################################
# findstr
#
# Search for files containing a specified string. Show the file path,
# line number, and the line itself containing a specified string.
#
# EXAMPLE:
#
# To search for all the files with the file extension .html containing
# a string "body" under the current directory and all its
# subdirectories, do:
#
# $ findstr . "*.html" "body"
#
find $1 -name \*$2 -exec grep -nH "$3" {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment