Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

I have multiple users on one machine with FreeBSD7.3. Each user has his own site (only one). Each site is a copy of master-site with slight differences (ie. database configuration, template files).
It's like many Wordpresses with different users on one machine.

The problem is:
I've made a patch for master-site. How i can update all of this sites at once, rightly changing user permissions and ownership.

IE: I have patch like it:


And i have many users with the same directory structure and few other files:




share|improve this question
up vote 2 down vote accepted

Here's a quick bash snippet that should do the trick for you.

I'm making an assumption that everything in /home that is a directory and matches *\.com is a site where you want to replace index.php and includes/system.php. If this logic is not suitable, you might have to make some modifications yourself.

I have tested it within limited constraints. Make sure that the ls -ld output in FreeBSD has the user in the third field and the group in the forth field. Also, --reply=yes is a GNUism. You might have to use -f or the BSD equivalent to force replacement of an existing file without interaction.

for D in `find /home -type d -name '*\.com'`
     myuser=`ls -ld $D | awk '{print $3}'`
     mygroup=`ls -ld $D | awk '{print $4}'`

     echo "Updating ${D}..."
     cp ${D}/index.php ${D}/index.php.ORIG
     cp ${D}/includes/system.php ${D}/includes/system.php.ORIG
     cp --reply=yes /path/to/temp/patch/www/index.php ${D}
     cp --reply=yes /path/to/temp/patch/www/includes/system.php ${D}/includes
     chown $myuser:$mygroup ${D}/index.php
     chown $myuser:$mygroup ${D}/includes/system.php
     echo "--------------------------------"
     echo ""
share|improve this answer
Brilliant! Delightfully! Magnificently! – kirillorloff Jul 28 '10 at 21:08

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.