Multiple file search and replace

The most concise way I found to do this is to use Perl:

perl -pi -w -e 's/search/replace/g;' *.txt

Bear in mind what’s between the single quotes after the -e option is a line of Perl code and the search argument is a regular expression, so some characters will have special meanings. You can escape special characters (like the forward-slash, dot, caret, dollar sign, and so on) by preceeding them with a back-slash.

Find files containing text

You can use grep for this. The -l switch outputs only the names of files in which the text occurs (instead of each line containing the text), the -i switch ignores the case, and the -r descends into subdirectories.

1 grep -lir "some text" *

Emacs grep-find command does it this way:

find . -type f -print0 | xargs -0 -e grep -nH -e "some text"

I have found it useful to find files containing two strings like this:

find . -type f -print0 | xargs -0 -e grep -H -e "some text" | xargs -e grep -H -e "other text"