Why does chmod +w not give write permission to other(o)

32,335

Solution 1

Your specific situation

In your specific situation, we can guess that your current umask is 002 (this is a common default value) and this explains your surprise.

In that specific situation where umask value is 002 (all numbers octal).

  • +r means ugo+r because 002 & 444 is 000, which lets all bits to be set
  • +x means ugo+x because 002 & 111 is 000, which lets all bits to be set
  • but +w means ug+w because 002 & 222 is 002, which prevents the "o" bit to be set.

Other examples

  • With umask 022 +w would mean u+w.
  • With umask 007 +rwx would mean ug+rwx.
  • With umask 077 +rwx would mean u+rwx.

What would have matched your expectations

When you change umask to 000, by executing

umask 000

in your terminal, then

chmod +w file

will set permissions to ugo+w.

Side note

As suggested by ilkkachu, note that umask 000 doesn't mean that everybody can read and write all your files.

But umask 000 means everyone that has some kind of access to any user account on your machine (which may include programs running server services ofc) can read and write all the files you make with that mask active and don't change (if the containing chain of directories up to the root also allows them).

Solution 2

With:

chmod +<perms>

the perms are added to user, group and other but with the umask still applying. It makes sure the file is not granted more permission than a newly created file would.

If you want to add the perms to user, groups and other regardless of the umask, use

chmod a+<perms>

which is short for

chmod ugo+<perms>
Share:
32,335

Related videos on Youtube

Ravi Sevta
Author by

Ravi Sevta

I'm MEAN stack developer. and love to code in JavaScript, Java.

Updated on September 18, 2022

Comments

  • Ravi Sevta
    Ravi Sevta over 1 year

    When I run chmod +w filename it doesn't give write permission to other, it just gives write permission to user and group.

    After executing this command

    chmod +w testfile.txt
    

    running ls -l testfile.txt prints

    -rw-rw-r-- 1 ravi ravi 20 Mar 10 18:09 testfile.txt
    

    but in case of +r and +x it works properly.

    I don't want to use chmod ugo+w filename.

  • Ravi Sevta
    Ravi Sevta about 6 years
    yes, but i think +w gives permission to all( user, group and other).
  • Jaken551
    Jaken551 about 6 years
    To give permissions to all users, use chmod a+w testfile.txt. Use u for user, g for group, o for other, and a for all.
  • Ravi Sevta
    Ravi Sevta about 6 years
    if chmod a+w filename, chmod +w filename and chmod ugo+w filename are alternative to each other then why not just use +w
  • Prvt_Yadav
    Prvt_Yadav about 6 years
    It means that +x and a+x are not equal.
  • StarWeaver
    StarWeaver about 6 years
    umask 000 means everyone that has some kind of access to a user account on your machine (which may include programs running server services ofc) can read and write all the files you make with that mask active and don't change, to be clear
  • Chris
    Chris about 6 years
    I like to have links: man7.org/linux/man-pages/man1/chmod.1.html „If none of these are given, the effect is as if (a) were given, but bits that are set in the umask are not affected.“
  • ilkkachu
    ilkkachu about 6 years
    "+r means ugo=r" -- no, it doesn't, it means to set the r bit for those parties where the umask allows it. This is clearly stated in the manuals of e.g. GNU chmod and FreeBSD chmod, as well as the standard. Same for +x. For +w you're right, for the case of that particular umask.
  • ilkkachu
    ilkkachu about 6 years
    Also, setting umask to 0 doesn't mean that everybody can read and write all your files, since many applications create files that are particularly private with mode 0600, meaning that the group and others don't get any access, regardless of the umask.
  • Prvt_Yadav
    Prvt_Yadav about 6 years
    @ilkkachu +r means ugo=r, this was related to the situation described in the question. That was not general.
  • ilkkachu
    ilkkachu about 6 years
    @Debian_yadav, that's exactly the point: the umask is an important part of how +r behaves, not a sidenote. Besides, even assuming umask 002, chmod +r doesn't mean chmod ugo=r, it means chmod ugo+r
  • Stéphane Gourichon
    Stéphane Gourichon over 4 years
    This answer, while partly true, is misleading and should not be as is the accepted answer. It could be improved. By comparison @chazelas answer is totally true, yet still a little short for someone not familiar with umask.
  • Prvt_Yadav
    Prvt_Yadav over 4 years
    @StéphaneGourichon why don't you explain, how it is misleading?
  • Stéphane Gourichon
    Stéphane Gourichon over 4 years
    @Prvt_Yadav Basically, readers of this question will often be beginners, and often only read the beginning of your answer. Comments already pointed out the problems. As a result, I offered an edit to the answer.
  • Prvt_Yadav
    Prvt_Yadav over 4 years
    @StéphaneGourichon thanks for the suggestion, I approved it, but as beginners will not understand it, it doesn't mean it is misleading.