Very useful search and replace command for the linux command line. This command is made up of a find command to find the files that you want and a perl command to do the text replacement.

The first part “find . -type f -name “*.html” -print” finds all of the files starting at the current directory that end with .html. The “-type f” makes sure that only files are found and not directories. The string that comes after the -name parameter is the filename to find. The -print parameter just prints the
the relative path to the found file.

The -exec parameter is used to execute a command with the found file. Everything after the -exec is executed until it reaches “;”.

The command that is executed on each file is a perl command that does the find and replace.

Breakdown of perl command:

-e means execute the following line of code.
-i means edit in-place
-w write warnings
-p loop

Then the part between the single quotes is the line of code which is a command to find all occurrences of oldsite.com and replace it with
newsite.com. The periods are reserved characters so they need to be escaped with a back-slash.

Date posted: May 15, 2010 | Author: | No Comments »

Categories: Linux

Tags: ,

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright © 2013, Neil Bittner. All Rights Reserved.