WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

migrated from stackoverflow.com Aug 31 '11 at 11:31

This question came from our site for professional and enthusiast programmers.

This seems like a question for SuperUser. I'm sure some combination of piping, echo, and the file names from the command line will fix the configs. – PhpMyCoder Aug 31 '11 at 10:58
Are all the sites on the same server? – hakre Aug 31 '11 at 11:23
As stated below, you shouldn't just append this to your wp-config.php file, as it will create unexpected results. Additions to wp-config.php need to come before the line that says /* That's all, stop editing! Happy blogging. */. – helenhousandi Aug 31 '11 at 13:07
Close-voted as off-topic. Modifying files on a server via SSH is not a WordPress question. – Chip Bennett May 25 '12 at 3:10

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) 
sed -i 1i"define('<?php WP_CACHE', true); ?>" $i

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

share|improve this answer
He would still have to manually specify every file using this method so I am not sure it answer the question from that point of view. – Treffynnon Aug 31 '11 at 11:37
By this way, you'll end up adding it even before <?php. Can somehow the line number be specified? – petermolnar Aug 31 '11 at 11:56
In fact the command sed -i 1i means : insert text before line 1. You could specify any line number. – drcelus Sep 1 '11 at 21:43

This will search the server recursively from root (/) for all files named wp-config.php and append the string define('WP_CACHE', true); onto the end of the file.

find / -name "wp-config.php" -print | while read i; do echo "define('WP_CACHE', true);" >> "$i"; done
share|improve this answer
I think you will find your site to behave in an unexpected way if you start putting things at the very bottom of your wp-config.php. Things you add need to come before the line that says /* That's all, stop editing! Happy blogging. */. – helenhousandi Aug 31 '11 at 12:46
Oh I see I know nothing about Wordpresses configuration files and answered with exactly what @SergioPellegrini asked for. This comment should really be made on the question in that case so he is aware. – Treffynnon Aug 31 '11 at 12:53
I see, you probably answered this before it was migrated to WordPress SE. I will add the comment above. – helenhousandi Aug 31 '11 at 13:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.