Fix file permissions

#!/bin/bash
 
for DIR in /media/bilder /media/lagerliste /media/projekte /media/texte; do
    echo ${DIR}
 
    echo "set owner..."
    find ${DIR} \! -user nobody -exec chown nobody {} \;
    find ${DIR} \! -group nogroup -exec chgrp nogroup {} \;
#    chown nobody:nogroup ${DIR} -R
 
    echo "set directory permissions..."
    find ${DIR} \! -perm 777 -type d -exec chmod 777 {} \;
#    find ${DIR} -type d -exec chmod 777 {} \;
 
    echo "set file permissions..."
    find ${DIR} \! -perm 666 -type f -exec chmod 666 {} \;
#    find ${DIR} -type f -exec chmod 666 {} \;
done
 
echo "remove lock files..."
find /media/ -name ".~lock*" -exec rm {} \;
 
echo "remove backup files..."
find /media/ -name "*~" -exec rm {} \;