11

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!

2 Answers 2

18

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

4
  • Thanks! Matthew for solving the issue and for providing an informative link, that just got bookmarked :-)
    – Linux NewB
    Commented Feb 12, 2014 at 11:26
  • If you found this useful please mark as answer. Commented Feb 12, 2014 at 11:34
  • won't that make all the files inside the folder executable?
    – stib
    Commented Feb 12, 2014 at 12:18
  • Yes it will, but from his question I gather that is what he wants. The link I provided will help him with his permissions. Since you mention it I shall update my answer to include a look at this. Commented Feb 12, 2014 at 12:19
1

You can use chmod to change the permission bits. The -R option is for recursively - used for directories. The bits are explained as rwx i.e. read, write and executable. If r =1, w =1 and x =1 . The binary 111 means 7 in decimal. Thus, you see 7. Now, the fields are decided as u = user, group, and others. So, if you want to give permission to everyone then you do chmod -R 777 dir_name. Also, you can say chmod -R a+rwx dir or if you want to remove some permission, then you can say that chmod -R a-x dir - this is to remove executable permission.

Also, you can do man on chmod to know more details.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .