Give permission to file/sub-directory only – Linux
Sometimes, you have to change permissions on all files within a directory or change permissions on all sub-directories in a directory.
You know, we use some commands to change permission such as “chmod” or “setfacl” or other commands.
But in this scenario, we want to changes all files permission in a directory and its sub-directories or change permission for all sub-directories.
There is a regular command:
chmod -R 755 /DirectoryPath
Read and execute permissions will be granted by this command to all your directories and files but this is not working for our scenario.
You can run the below command for give proper permissions to directory or sub-directories:
find /path/to/base/dir -type d -exec chmod 755 {} +
Or
chmod 755 $(find /path/to/base/dir -type d)
Or
find /path/to/base/dir -type d -print0 | xargs -0 chmod 755
Also you can run same commands for files:
find /path/to/base/dir -type f -exec chmod 644 {} +
Or
chmod 644 $(find /path/to/base/dir -type f)
Or
find /path/to/base/dir -type f -print0 | xargs -0 chmod 644
I hope, this post will help you to address your some permission issues.