Performing actions on all your WordPress installations

2013-12-20

With this simple shell script, you can perform actions on all of your WordPress installations at the same time. This particular example changes the file ownership, but you can easily modify it to run the commands you need. It is based on my previous post about searching for WordPress installations.

#!/bin/bash

for wp_config_file in $(find /var/www/ -type f -name 'wp-config.php' -print0 | tr '\0' '\040')
do
        this_wp_directory=$(echo "$wp_config_file" | replace '/wp-config.php' '')
        chown -R root:root $this_wp_directory
        chown -R www-data:www-data $this_wp_directory/wp-content/uploads
        echo "Fixed file permissions on $this_wp_directory"
done