Quantcast
Channel: Anil Konsal
Viewing all articles
Browse latest Browse all 10

Find and Replace text in multiple files in Linux

$
0
0

Its quite easy for finding and replacing some text contained in the editable files in Linux with ‘sed’ command. Below is a case to replace some text in all the php files on the server containing text ‘old_text’ to ‘new_text':

1
find public_html/ -type f -name "*.php" | xargs sed -i 's/old_text/new_text/g'

The First part before pipe (|) sign find s the file with php extension and the second part of file finds and replaces the text in the found file.

Easy enough :)

Keep Hacking!


Viewing all articles
Browse latest Browse all 10

Trending Articles