Site icon Haktan Suren, PhD

Find & Replace Recursively in a directory (Perl)

If you happen to substitute every instances of foo with bar in a specific directory, you can simply use the following shell script.

perl -e "s/foo/bar/g;" -pi $(find /path/to/dir -type f)

You should escape the “/”. Following example will replace foo/foo with barbar

perl -e "s/foo\/foo/barbar/g;" -pi $(find /path/to/dir -type f)
Exit mobile version