for u in `ls`; do if [ -d $u/domains ]; then # Get UID of directory name uid=$(stat -c "%u" $u); find $u -user $uid -exec chown $u "{}" \; ; gid=$(stat -c "%g" $u); find $u -group $gid -exec chgrp $u "{}" \; ; if [ -f $u/public_html ]; then chown -h $u:$u $u/public_html ; fi; fi; done;