[UPHPU] recursively set directories and files different permissions

Richard K Miller richardkmiller at gmail.com
Wed Jan 9 18:05:36 MST 2008

On Jan 9, 2008, at 5:21 PM, Wade Preston Shearer wrote:

> Is there a way to recursively set all directories permissions to one  
> thing and all files to another?
> The reason that I ask is because I have a directory (and everything  
> within it) on a website where non-script files (images, style  
> sheets, PDFs, etc) are located and I want to ensure that a script  
> file (PHP) cannot be placed in there and executed.
> I tried removing execution from everything but have discovered that  
> I then cannot cd into them. So, it appears that I need all of the  
> directories to have execution, but not the files. Don't files  
> inherit permissions from their parent directories though? So any new  
> files would get execution permissions and my work would be for  
> naught? How do people get around this?

My understanding is that the default permissions for directories are  
0755 and for files 0644, which turns on execution for directories but  
not files. If you need to change the defaults, you use the umask:


For changing existing directories, you might use a command like this:
find . -type d | xargs -I% chmod 0755 %

And for existing files:
find . -type f | xargs -I% chmod 0644 %

More information about the UPHPU mailing list