Recursive Find and Replace Linux Command Line Method


This article provides a guide for using recursive find and replace (Linux command line method) to efficiently replace data.

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 using sed command-line tool.

Using Recursive Find and Replace (Linux Command Line Method)

Follow the steps below to utilize the recursive 'Find and Replace' tool.

  1. Login to SSH terminal.
  2. 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'

How to Modify Command

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

For example, if we wanted to change every instance of "red" to "blue", we could run the following command:

egrep -lRZ 'red' . | xargs -0 -l sed -i -e 's/red/blue/g'

The command will find all instances of "red" and replace with "blue". Simply navigate to the directory that you want to recursively change and run the command.

You now know how to use recursive Find and Replace (Linux command line method).

  • file, replace, find, ssh commands, editing, command line
  • 10 Korisnici koji smatraju članak korisnim
Je li Vam ovaj odgovor pomogao?

Related Articles

View Server PHP Environment with phpinfo.php

The phpinfo() function outputs a huge amount of information about the system you're using, such...

How to Change Root Password Using SSH

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

How to Create Sudo User on CentOS

This article provides step-by-step setup guide for adding Sudo user to CentOS system. The sudo...

How to Use Sudo

This article provides a guide to using a Sudo user on CentOS server. From the command line,...

Set Server Time Zones with Timedatectl

This article provides a guide to setting the server time and server time zone settings using...