Recursive Find and Replace Command Line Method

Reference this guide for help with mass find and replace file manipulation in Linux servers.

Find and Replace text strings recursively through all files and sub-folders of a particular directory.

Run the following command from SSH terminal:

egrep -lRZ 'old-text-string' . | xargs -0 -l sed -i -e 's/old-text-string/new-text-string/g'

This command will recursively replace every instance of "old-text-string" with "new-text-string. Modify the command to best meet your needs.

Was this answer helpful?

 Print this Article

Also Read

Remove Login History on Server

On the Linux systems there are three standard commands that show the information about last...

View Server PHP Environment with phpinfo.php

Enable Browser Caching with .htaccess File

Enable browser caching to reduce website loading times, by taking advantage of caching of...

How to Bind Additional IPs to Network Interface Card - CentOS

This article explains the process of binding multiple IP addresses to the Network Interface Card...

How to Change Root Password Using SSH

This article explains the method of changing the root password on a Linux Server using SSH. SSH...