Shell Script: Search for Strings in Web Files

I used this shell script to search through some web directories for references to particular strings – just for future reference.
The find command only greps in html, php and pdf files: the -o switch is an OR.

#!/bin/bash
PATHTOSEARCH=/path/to/webroot
FIND=/usr/bin/find
NICE=/bin/nice
PATTERN=’Media,1234,en.pdf|Media,1235,en.pdf|Media,1236,en.pdf’

$NICE $FIND $PATHTOSEARCH -type f \( -name ‘*.html’ -o -name ‘*.php’ -o -name ‘*.htm’ -o -name ‘*.pdf’ \) -exec egrep “$PATTERN” {} \; -print

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>