I have a directory with millions of files and sub directories and I need to change the permissions on the entire directory and its files and its take many hours to do this. I was wondering if there is a quicker way of doing this than the normal chmod -R command?
Your chmod -R is quite optimal. There have to be one chmod() syscall per file and filesystem has to update it's metadata on block device.
Disable barriers (mount option on XFS, Ext4 etc.) on this FS if enabled but remember to enable them later.
I hope it's one time action and not recurring problem? If easy management of file permissions is more important than performance and simplicity you could try to write some overlay FUSE filesystem mangling permissions and uid/gid on-the-fly.
You'd want to write a script and execute from the root directory. I think a basic one would go something like this;
Etc, etc, etc... There might be a better script or a better way. I'm not very good at scripting.