How do I change permissions for a folder and its subfolders/files?
The other answers are correct, in that chmod -R 755
will set these permissions to all files and subfolders in the tree. But why on earth would you want to? It might make sense for the directories, but why set the execute bit on all the files?
I suspect what you really want to do is set the directories to 755 and either leave the files alone or set them to 644. For this, you can use the find
command. For example:
To change all the directories to 755 (drwxr-xr-x
):
find /opt/lampp/htdocs -type d -exec chmod 755 {} \;
To change all the files to 644 (-rw-r--r--
):
find /opt/lampp/htdocs -type f -exec chmod 644 {} \;
Some splainin': (thanks @tobbez)
chmod 755 {}
specifies the command that will be executed byfind
for each directorychmod 644 {}
specifies the command that will be executed byfind
for each file{}
is replaced by the path;
the semicolon tellsfind
that this is the end of the command it's supposed to execute\;
the semicolon is escaped, otherwise it would be interpreted by the shell instead offind
Chmod 777 to a folder and all contents
If you are going for a console command it would be:
chmod -R 777 /www/store
. The -R
(or --recursive
) options make it recursive.
Or if you want to make all the files in the current directory have all permissions type:
chmod -R 777 ./
If you need more info about chmod
command see: File permission
Set permissions for directorys/subdirectorys/files
You have to add another AccessRule with InheritanceFlags set to ContainerInherit AND ObjectInherit.
To get the permissions to propgate to child folders, the PropagationFlag is set to Inherit only.
Here's an example below
public void PropogateSecurity(string userid,string directory)
{
var myDirectoryInfo = new DirectoryInfo(directory);
var myDirectorySecurity = myDirectoryInfo.GetAccessControl();
myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(userid, FileSystemRights.Modify, InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow));
myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(userid, FileSystemRights.Modify, InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow));
myDirectoryInfo.SetAccessControl(myDirectorySecurity);
}
You can also do this with recursion, but the above would be my preferred method as cleaning up permissions would be annoying.
Permission denied from a subfolder
The issue was coming from PHP 5.6.26. Using PHP 5.6.40 fixed it.
I reset to my original permissions and everything is fine!
Related Topics
Save Modifications in Place With Awk
How to Pass Command Output as Multiple Arguments to Another Command
How to Analyze a Program'S Core Dump File With Gdb When It Has Command-Line Parameters
What Is Better "Int 0X80" or "Syscall" in 32-Bit Code on Linux
How to Make an Executable Elf File in Linux Using a Hex Editor
How to Normalize a File Path in Bash
My Shell Script Stops After Exec
How to Count Lines in a Document
How to Syntax Check a Bash Script Without Running It
Why Should Eval Be Avoided in Bash, and What Should I Use Instead
How to 'Grep' a Continuous Stream
Can Windows Containers Be Hosted on Linux
Adding a New Entry to the Path Variable in Zsh
Setting Environment Variables in Linux Using Bash
Which Linux Ipc Technique to Use
Minimal Executable Size Now 10X Larger After Linking Than 2 Years Ago, For Tiny Programs