Linux – How to change permissions on a directory

centoschmodfile-permissionslinux

I'm using CentOS and I would like to know how to change permissions on a folder with multiple files in it.

I have used the following commands on the folder as root (Let's say folder =A) :

chmod 777 (home/directory/A)

chmod g+r (A)

If I view the folder as a normal user, using the file manager, the lock icon is not visible which indicates that the permissions have been granted? however all the files within folder A still show a lock icon indicating that just folder A has been granted permission and none of the sub-directories within it.

It will prove to be quite a laborious task to run the commands mentioned above on all the sub-directories as there are simply too many.

Thanks!

Best Answer

In order to set permissions on the folder and all sub folders/files you need to use the recursive option in your command:

chmod 777 -R /path/to/directory

For more information using chmod please see here.

UPDATE:

Disclaimer: Using chmod 777 will make your folder executable by everyone. Please see below for a look at setting

Your permissions are set using three numbers.

the 100's are for the owner of the file
400 read
200 write
100 execute

10's are for the group of the file
40 read
20 write
10 execute

1's are for everyone else
4 read
2 write
1 execute

In your example you are giving owner, group and everyone full rights to your file. If, for example, you wish to give owner and group full permissions, but everyone else only read and execute permissions you would use 775.

If you wish to use letter representation instead of numbers please see here

Related Question