Sometime we need to search and replace some string in all files located in particular directory or all sub-directory.
This scenario could be possible with combination of grep and sed command. Let’s take an example in which we want to change word eth0 to eth1 in complete /etc directory including sub-directory.

Just for precaution, I have taken backup of my /etc in /root/back_etc.

#grep -rl eth0 . 2> /dev/null

Content of line in file

# grep -r eth0 . 2> /dev/null
./samba/smb.conf:; interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24
./udev/rules.d/70-persistent-net.rules:SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:09:a3:b7", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
./ppp/ip-up.ipv6to4:# Example: IPV6TO4_ROUTING="eth0-:f101::1/64 eth1-:f102::1/64"
./modprobe.d/dist.conf:install eth0394 /bin/true
./sysconfig/cbq/cbq-0000.example:DEVICE=eth0,10Mbit,1Mbit
./sysconfig/network-scripts/ifcfg-eth0:DEVICE=eth0
./sysconfig/network-scripts/ifup-aliases:# Specify multiple ranges using multiple files, such as ifcfg-eth0-range0 and
./sysconfig/network-scripts/ifup-aliases:# ifcfg-eth0-range1, etc. In these files, the following configuration variables
./sysconfig/network-scripts/ifup-aliases:# The above example values create the interfaces eth0:0 through eth1:253 using
./sysconfig/network-scripts/ifup-ipv6:# Example: IPV6TO4_ROUTING="eth0-:f101::1/64 eth1-:f102::1/64"

Let’s start search replacing of eth0 string to eth1 in all these files in one command.
for i in `grep -rl <String> . 2> /dev/null`; do sed -i ‘s/search-string/replace-string/’ $i; done

# for i in `grep -rl eth0 . 2> /dev/null`; do sed -i 's/eth0/eth1/' $i; done

# grep -r eth0 . 2> /dev/null

 # grep -r eth1 . 2> /dev/null
./samba/smb.conf:; interfaces = lo eth1 192.168.12.2/24 192.168.13.2/24
./udev/rules.d/70-persistent-net.rules:SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:09:a3:b7", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
./ppp/ip-up.ipv6to4:# Example: IPV6TO4_ROUTING="eth1-:f101::1/64 eth1-:f102::1/64"
./modprobe.d/dist.conf:install eth1394 /bin/true
./sysconfig/cbq/cbq-0000.example:DEVICE=eth1,10Mbit,1Mbit
./sysconfig/network-scripts/ifcfg-eth0:DEVICE=eth1
./sysconfig/network-scripts/ifup-aliases:# Specify multiple ranges using multiple files, such as ifcfg-eth1-range0 and
./sysconfig/network-scripts/ifup-aliases:# ifcfg-eth1-range1, etc. In these files, the following configuration variables
./sysconfig/network-scripts/ifup-aliases:# The above example values create the interfaces eth1:0 through eth1:253 using
./sysconfig/network-scripts/ifup-ipv6:# Example: IPV6TO4_ROUTING="eth1-:f101::1/64 eth1-:f102::1/64"

# grep -rl eth1 . 2> /dev/null
./samba/smb.conf
./udev/rules.d/70-persistent-net.rules
./ppp/ip-up.ipv6to4
./modprobe.d/dist.conf
./sysconfig/cbq/cbq-0000.example
./sysconfig/network-scripts/ifcfg-eth0
./sysconfig/network-scripts/ifup-aliases
./sysconfig/network-scripts/ifup-ipv6

Below image for same
subsititue string from complete directory