FindGrepTips
Zur Navigation springen
Zur Suche springen
tricks with find, grep
find . -type f -exec grep "<sub-string>" {} \; -print Find files (and content) containing <sub-string> within directory tree
Description: This will search all files recursively through the current directory tree and look for the <sub-string> specified. The filename will be printed after all occurrances of <sub-string> within the file and the context in which the sub-string was found. This is useful for searching through script files looking for strings that may need to be changed or updated. Depending on size of directory, command can take a little time and output could get lengthy. tricks with find, grep and perl
Linux example - find and grep, and perl replacement to fix a spelling error.
find ./ -type f -name '*.htm*' -exec grep Galations {} \; find ./ -type f -name '*.txt' -exec grep Galations {} \; find ./ -type f -name '*.htm*' -exec perl -pi -e 's/Galations/Galatians/g' {} \; find ./ -type f -name '*.txt' -exec perl -pi -e 's/Galations/Galatians/g' {} \;
Keywords: grep,find,perl,exec,replace,string,sub-string