Search and replace text in all files of a linux directory

21,041

Solution 1

The following will do it:

sed -i 's/old_link/new_link/g' file...

Don't forget to escape any slashes, dots, and any other regex special chars in the link addresses with a backslash.

Solution 2

Also, try:

perl -p -i -e <regex> <folder>
Share:
21,041
Yarin
Author by

Yarin

Products PDF Buddy - Popular online PDF editor Gems Snappconfig - Smarter Rails app configuration

Updated on December 17, 2020

Comments

  • Yarin
    Yarin over 3 years

    I have a website directory where I need to change all hardcoded links from one domain to another. Looking for a single (grep? sed?) bash command that will allow me to change all occurrences of text in all files in the directory?