Linux: Search and replace in files


Just a quick recipe for performing search & replace on many files at once.


  • Replace $NAME with find match specifier, e.g. “*.php”
  • Replace $SEARCH_LITERAL and $REPLACE_LITERAL with unquoted search/replace strings
    • Search/replace strings must escape forward-slash(/) with back-slash(\), e.g. http:\/\/

Example to perform replace all occurrences of foo with bar in all php files

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">