Tech

How to Find and Replace a String in Multiple Files on MacOS Command Line

Photo of Zac VineyardZac Vineyard
May 25th, 2024

Say you have a pile of HTML files on your computer, but you have a problem. A string of charachters found in every file needs to be changed. Well, here's the magic sauce you can run on command line to change that string.

find . -type f -name '*.html' -exec sed -i '' 's/find/replace/g' {} +

This command is a mix of find and sed commands to search out a string and replace it in multiple files.

Copyright © Zachary Vineyard