Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set permissions for all files and folders recursively

Tags:

I want to recursively set the folder and file permissions. Folders should get 750 and files 644. I found this and made some adaptions. Would this one work?

<?php  function chmod_r($Path) {    $dp = opendir($Path);    while($File = readdir($dp)) {       if($File != "." AND $File != "..") {          if(is_dir($File)){             chmod($File, 0750);          }else{              chmod($Path."/".$File, 0644);              if(is_dir($Path."/".$File)) {                 chmod_r($Path."/".$File);              }          }       }    }    closedir($dp); }  ?>  
like image 730
testing Avatar asked Feb 13 '12 14:02

testing


People also ask

How do I chmod all folders and subfolders?

Use chmod -R 755 /opt/lampp/htdocs if you want to change permissions of all files and directories at once. Use find /opt/lampp/htdocs -type d -exec chmod 755 {} \; if the number of files you are using is very large.

What is the meaning of chmod 777?

Setting 777 permissions to a file or directory means that it will be readable, writable and executable by all users and may pose a huge security risk.

How do I set permissions to all files in a directory?

To change directory permissions for everyone, use “u” for users, “g” for group, “o” for others, and “ugo” or “a” (for all). chmod ugo+rwx foldername to give read, write, and execute to everyone. chmod a=r foldername to give only read permission for everyone.


1 Answers

Why don't use find tool for this?

exec ("find /path/to/folder -type d -exec chmod 0750 {} +"); exec ("find /path/to/folder -type f -exec chmod 0644 {} +"); 
like image 163
Sergey P. aka azure Avatar answered Oct 20 '22 11:10

Sergey P. aka azure