The task: we need to change the permissions or the owner (chmod or chown, respectively) of all nested files or directories. But only files, or only directories. The standard chmod -R or chown -R method won't work, since it acts on both files and directories.
What we need is for it to walk through all directories and change only files, or only directories. For example, we set chmod on directories to 775... but 775 for files doesn't mean the same thing as for directories — for files the correct value is 664.
So, let's solve it.
To change chmod or chown for directories only, starting from the directory you are in (i.e., unlike chmod -R, you need to cd into the directory from which you want to change permissions):
# find . -type d -exec chmod 775 {} \;
# find . -type d -exec chown aaa:bbb {} \;
Instead of 775, put the chmod value you need. And instead of aaa:bbb, put the user and group you need, respectively.
To change permissions for files only (or the owner):
# find . -type f -exec chmod 664 {} \;
# find . -type f -exec chown aaa:bbb {} \;
Comments