# chmod'ing a directory with millions of files taking forever

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;

chmod 777 ./stuff/stuff
chmod 777 ./stuff/stuff

chmod 666 ./stuff/stuff
chmod 666 ./stuff/stuff


Etc, etc, etc... There might be a better script or a better way. I'm not very good at scripting.

-
I'm basically doing chmod -R 777 /dir/ –  Eric Fouarge Feb 10 '12 at 16:42
writing a script to chmod files one at a time is guaranteed to be slower –  stew Feb 10 '12 at 21:22