in ,

GeekGeek

Search and replace in Linux – one line command

If you work in the web hosting industry, I’m pretty sure you encountered situations when you have to search and replace a string in multiple files.

As a practical example, maybe you have to search for an old IP (123.123.123.123) in all the DNS zones of your server and replace that IP with a new one (222.222.222.222). Well, it might sound complicated, but with a simple command, you can do this in seconds:

find /path/to/directory -name "*.txt" | xargs perl -pi -e 's/123.123.123.123/222.222.222.222/g'

Of course, you have to replace the path where all those files are located, the extension of the files on which you want to make the replacement (or you can simply use * if you want to replace in ALL kind of files) and the IPs with your own.

NOTE: is not necessary to replace numbers only, it works for any kind of strings.

I hope it helps 🙂 Cheers!

How to get $10 for free? This is my gift for you on Revolut, get it NOW!

[SOLUTION] How to efficiently increase WordPress memory frontend and backend?