{"id":13,"date":"2008-02-01T23:00:30","date_gmt":"2008-02-02T04:00:30","guid":{"rendered":"http:\/\/gabeanderson.com\/2003\/02\/20\/unixlinux-find-replace-in-multiple-files\/"},"modified":"2008-02-12T18:56:37","modified_gmt":"2008-02-12T23:56:37","slug":"unixlinux-find-replace-in-multiple-files","status":"publish","type":"post","link":"https:\/\/gabeanderson.com\/tech-blog\/2008\/02\/01\/unixlinux-find-replace-in-multiple-files\/","title":{"rendered":"Unix\/Linux Find &#38; Replace in Multiple Files"},"content":{"rendered":"<p>Here&#8217;s a classic that I originally published <strong>20 February 2003 &#8211; 11:14<\/strong>. This entry was the #1 most popular post between 11\/19\/2005 and 11\/13\/2006, receiving 16,443 page views (13,653 unique) during that time.<\/p>\n<hr>\n<p>Since it&#8217;s damn near impossible to find online the simplest way to scan a Unix directory of files, search for one text pattern, and replace with another, I am now archiving the simplest method I could find (which I&#8217;ve tested and have proven that it works beautifully). Simply <i>cd<\/i> to the directory where your files live, modify (or leave) the <i>*.php<\/i> to match the file type you are modifying, then run the following at the command line:<\/p>\n<ul>\nfor fl in *.php; do<br \/>\nmv $fl $fl.old<br \/>\nsed &#8216;s\/FINDSTRING\/REPLACESTRING\/g&#8217; $fl.old &gt; $fl<br \/>\n#rm -f $fl.old<br \/>\ndone\n<\/ul>\n<p>Uncomment <i>rm -f $fl.old<\/i> if you don&#8217;t want to bother keeping a copy of the old files. Simple, eh? It&#8217;s all about <i>sed<\/i>, baby.<\/p>\n<p><a title=\"Replace a string in several text files\" href=\"http:\/\/www.experts-exchange.com\/Operating_Systems\/Linux\/Q_10515858.html#1\">Linux: Replace a string in several text files<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s a classic that I originally published 20 February 2003 &#8211; 11:14. This entry was the #1 most popular post between 11\/19\/2005 and 11\/13\/2006, receiving 16,443 page views (13,653 unique) during that time. Since it&#8217;s damn near impossible to find online the simplest way to scan a Unix directory of files, search for one text [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,11],"tags":[],"class_list":["post-13","post","type-post","status-publish","format-standard","hentry","category-scripts","category-unix-linux"],"_links":{"self":[{"href":"https:\/\/gabeanderson.com\/tech-blog\/wp-json\/wp\/v2\/posts\/13","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gabeanderson.com\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gabeanderson.com\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gabeanderson.com\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gabeanderson.com\/tech-blog\/wp-json\/wp\/v2\/comments?post=13"}],"version-history":[{"count":0,"href":"https:\/\/gabeanderson.com\/tech-blog\/wp-json\/wp\/v2\/posts\/13\/revisions"}],"wp:attachment":[{"href":"https:\/\/gabeanderson.com\/tech-blog\/wp-json\/wp\/v2\/media?parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gabeanderson.com\/tech-blog\/wp-json\/wp\/v2\/categories?post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gabeanderson.com\/tech-blog\/wp-json\/wp\/v2\/tags?post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}