Recursively change only directory permissions on Linux (Chmod)

by Strider on September 7, 2009

in Tips 'n' Tricks

Ever wondered how to chmod the  directories recursively  in Linux? I was trying out a PHP script which requires the root directory and  all the sub-directories  under it to be chmodded to full permissions, 777 keeping the existing file permissions intact.

After a bit of searching I found the simple yet powerful solution using the command find.  The following shell command will do the job where /xxx/xxx/xxx indicates the path of the root directory that needs to be recursively chmodded!

find /xxx/xxx/xxx -type d -exec chmod 777 {} \;

The switch -type d ensures that only directories are applied with the chmod command.

It’s clear that find can be used in all kind of batch operations; just specify the required command after the switch -exec.


The commandline -type d can be modified to -type f to change the permissions of all the files instead of directories.

{ 2 comments… read them below or add one }


1 February 22, 2010 at 7:38 am Thumb up 0 Thumb down 0

Thanks! Works like a charm on a Mac.



2 June 20, 2012 at 11:11 pm Thumb up 0 Thumb down 0

hm. I get a message saying, “find: missing argument to ‘-exec'”…


Leave a Comment

Previous post:

Next post: