Update Directory and File Permissions Separately
Update Directory and File Permissions Separately
Multiple times I’ve needed to apply a different set of permissions on files verses folders; commonly when configuring web applications. Below is a quick walk-through on how to achieve this goal.
Directories
For directories, run find
ensuring -type
is set to d
. This tells find
to locate all directories recursively and execute a permission change of 755
only to directories.
find [path] -type d -exec chmod 755 {} \;
Files
For files, its a similar process with -type
is set to f
, for files. In this case, we don’t typically want to execute permissions on files unless they’re a script or executable so we’ll configure the permissions to be 644
.
find [path] -type f -exec chmod 644 {} \;
Thats all there is to it. If you run ls -l
on the top-level directory, you’ll see all directories now have the permission of 755
, with files set to 644
.