Find & Replace Recursively in a directory (Perl)

By Haktan Suren, PhD
In Blog
May 7th, 2013
0 Comments
3990 Views

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)

About the Author

Haktan Suren, PhD
- Webguru, Programmer, Web developer, and Father :)

Wrap your code in <code class="{language}"></code> tags to embed!

Leave a Reply

E-mail address is required for commenting. However, it won't be visible to other users.

Loading Facebook Comments ...
Loading Disqus Comments ...