hd. hd. - 3 months ago 16
Linux Question

Find and replace with sed in directory and sub directories

I run this command to find and replace all occurrences of 'apple' with 'orange' in all files in root of my site:

find ./ -exec sed -i 's/apple/orange/g' {} \;


but it doesn't go through sub directories.

what is wrong with this command?

Edited: here is some lines of output of find ./ command:

./index.php
./header.php
./fpd
./fpd/font
./fpd/font/desktop.ini
./fpd/font/courier.php
./fpd/font/symbol.php

Answer

Your find should look like that to avoid sending directory names to sed:

find ./ -type f -exec sed -i -e 's/apple/orange/g' {} \;