No grep needed. Just use find. This command
Code:
find $DIRNAME -type f -exec chmod 640 {} \;
will recurse int $DIRNAME, find everything that's just a regular file, and do a chmod 640 on it. The '-type f' tells find to return regular files, while the -exec performs the command after it. The {} in the chmod command stands for the file currently being processed. You must end the exec option with a semi-colon, which you'll probably have to escape.
You could modify this to change permissions on just the directories by changing the '-type f' to '-type d', for directory.
You can read more in the man page, but I find the reference and examples in
Linux in a Nutshell much better.