Fix My Computer, Mark! - Search & Replace a Name in Files 

Search & Replace a Name in Files

A little SSH script to search for a name in All files on your server.

Copy and Paste the code below and save it in a file called:

replacename.php 

<?php
echo shell_exec('
#!/bin/bash
find ./ -type f -exec sed -i \'s/oldname/newname/\' {} \;
');
?>

 

OR If that does not work...try this:

 

<?php
echo shell_exec('
#!/bin/bash
perl -pi -w -e \'s/oldname/newname/g;\' $( grep -rl \'oldname\' )
');
?>


Run it in the main directory, or in just the directory you want to search and replace a name in all the files in the directory on your server or your web host account.
Replace "oldname" and "newname".

 

Click to listen highlighted text!