How do I change permissions on a directory

113,986

Solution 1

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

Solution 2

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.

Share:
113,986

Related videos on Youtube

Linux NewB
Author by

Linux NewB

Updated on September 18, 2022

Comments

  • Linux NewB
    Linux NewB over 1 year

    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!

  • Linux NewB
    Linux NewB over 10 years
    Thanks! Matthew for solving the issue and for providing an informative link, that just got bookmarked :-)
  • Gaurav Joseph
    Gaurav Joseph over 10 years
    If you found this useful please mark as answer.
  • stib
    stib over 10 years
    won't that make all the files inside the folder executable?
  • Matthew Williams
    Matthew Williams over 10 years
    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.