Why does chmod +w not give write permission to other(o)
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
meansugo+r
because002 & 444
is000
, which lets all bits to be set+x
meansugo+x
because002 & 111
is000
, which lets all bits to be set- but
+w
meansug+w
because002 & 222
is002
, which prevents the "o" bit to be set.
Other examples
- With
umask 022
+w
would meanu+w
. - With
umask 007
+rwx
would meanug+rwx
. - With
umask 077
+rwx
would meanu+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>
Related videos on Youtube
Ravi Sevta
I'm MEAN stack developer. and love to code in JavaScript, Java.
Updated on September 18, 2022Comments
-
Ravi Sevta over 1 year
When I run
chmod +w filename
it doesn't give write permission toother
, it just gives write permission touser
andgroup
.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 about 6 yearsyes, but i think
+w
gives permission to all( user, group and other). -
Jaken551 about 6 yearsTo give permissions to all users, use
chmod a+w testfile.txt
. Useu
for user,g
for group,o
for other, anda
for all. -
Ravi Sevta about 6 yearsif
chmod a+w filename
,chmod +w filename
andchmod ugo+w filename
are alternative to each other then why not just use+w
-
Prvt_Yadav about 6 yearsIt means that +x and a+x are not equal.
-
StarWeaver about 6 yearsumask 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 about 6 yearsI 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 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 about 6 yearsAlso, 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 mode0600
, meaning that the group and others don't get any access, regardless of the umask. -
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 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 umask002
,chmod +r
doesn't meanchmod ugo=r
, it meanschmod ugo+r
-
Stéphane Gourichon over 4 yearsThis 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 over 4 years@StéphaneGourichon why don't you explain, how it is misleading?
-
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 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.