How to use bash to recursively search and replace a string in all directory files
Another achievement I unlocked with the recent website update is the newsletter switch from Substack to a fantastic and independent provider, Buttondown. That required updating all the “subscribe to my newsletter” links. We’re talking 5K posts, all saved as individual files in the same directory. The bash command that did that for me is: find content/post/*.md -type f -exec \ sed -i .bak 's|https://nicolaiarocci.substack.com|https://buttondown.email/nicolaiarocci|g' {} + It is pretty straightforward. find looks for all markdown files in the content/post/ directory. On each file, sed performs a search-and-replace action. Notice that I use | instead of the standard / as a separator for the search-and-replace pattern , and that’s because the pattern itself has /s in the URLs so I need to differentiate. Also, on macOS, the -i parameter requires a backup file argument ("*.bak") to make a backup copy before the update. This argument is unnecessary in newer sed versions and will perform an in-place update if not provided. ...

