Append code into wp-config.php

We have multiple wordpress sites and need to update the wp-config for w3 total cache. We have to append define('WP_CACHE', true); into the wp-config.php file. Is it possible to do this via ssh. I don’t want to have to go in and open each config file and add it myself.

Your help will be much appreciated.

2 Answers
2

This commands prepends a line at the beggining of yourfile

sed -i 1i"define('WP_CACHE', true);" yourfile

To look for many files named wp-config.php and prepend the same text, type this in the shell:

for i in $(find . -name wp-config.php) 
do
sed -i 1i"define('<?php WP_CACHE', true); ?>" $i
done

Run this from the main folder where you have all the WP sites.

Leave a Comment