Pi Day

Today is Pi Day, celebrated by math geeks worldwide. It is celebrated today because the date is sometimes written as 3.14. To celebebrate this day, you can look piday.org to see the first million decimal places of Pi. I won’t write them all here this time, because it would take forever to load the page.

Performing actions on all your WordPress installations

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

Searching for WordPress installations

If you have multiple WordPress installations on your web server, you may occasionally have to change the settings in the configuration of all of your sites. The following command allows you to find all installations from a starting directory.

find ./ -type f -name 'wp-config.php'

Personally I like to use the text editor nano when I do stuff like that, and nano can open multiple files one after the other with one command. So we can rewrite the previous command to this one to open all files in sequence:

nano $(find ./ -type f -name 'wp-config.php' -print0 | tr '\0' '\040')