chown/chgrp by directory name

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;

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.