{"id":3727,"date":"2024-07-11T05:42:26","date_gmt":"2024-07-11T05:42:26","guid":{"rendered":"https:\/\/voodoo.business\/blog\/?p=3727"},"modified":"2024-07-11T06:28:32","modified_gmt":"2024-07-11T06:28:32","slug":"find-in-files-and-replace-in-files-in-linux","status":"publish","type":"post","link":"https:\/\/www.voodoo.business\/blog\/2024\/07\/11\/find-in-files-and-replace-in-files-in-linux\/","title":{"rendered":"Find in files and replace in files in Linux"},"content":{"rendered":"\n<p>If you are looking for functionality similar to notepad++ functionality of replacing a string in all the files in a certain folder, Look no more, in linux this is a simple command<\/p>\n\n\n\n<p>Assuming you are on the command line and the directory containing the files is the active one (cd)<\/p>\n\n\n\n<p>the following line will replace foo with bar in all files on the current root directory but not in subdirectories<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sed -i -- 's\/foo\/bar\/g' *<\/pre>\n\n\n\n<p>If you want it to go recursively into sub directories, you can combine the above with the find command<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> find . -type f -exec sed -i 's\/foo\/bar\/g' {} +<\/pre>\n\n\n\n<p>if you want sed to backup the files before it does the replace, use the following command, you can replace the .bak with anything you like<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sed -i.bak -- 's\/foo\/bar\/g' *<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you are looking for functionality similar to notepad++ functionality of replacing a string in all the files in a certain folder, Look no more, in linux this is a simple command Assuming you are on the command line and the directory containing the files is the active one (cd) the following line will replace [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3727","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts\/3727","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/comments?post=3727"}],"version-history":[{"count":1,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts\/3727\/revisions"}],"predecessor-version":[{"id":3728,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts\/3727\/revisions\/3728"}],"wp:attachment":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/media?parent=3727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/categories?post=3727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/tags?post=3727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}