18

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.

  • 2
    askubuntu.com/a/718782/158442 – muru Mar 10 '18 at 13:01
  • 1
    If you don't want to use ugo, use a. – muru Mar 10 '18 at 13:02
  • yes, but i just want to know why +w not working. – Ravi Sevta Mar 10 '18 at 13:20
  • That's why I left two comments. – muru Mar 10 '18 at 13:22
  • @muru. You claim in your askubuntu answer that you reference above that "This behavior is POSIX-mandated, and so, not a bug". Please be advised that POSIX Application Usage text is non-normative and is therefore not mandated by POSIX. – fpmurphy Mar 11 '18 at 5:38
26

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).

| improve this answer | |
  • 4
    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 – StarWeaver Mar 11 '18 at 7:12
  • 4
    "+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 Mar 14 '18 at 10:09
  • 4
    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. – ilkkachu Mar 14 '18 at 10:09
  • @ilkkachu +r means ugo=r, this was related to the situation described in the question. That was not general. – Prvt_Yadav Mar 14 '18 at 11:06
  • 2
    @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 – ilkkachu Mar 14 '18 at 13:09
25

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>
| improve this answer | |
0

You need to specify to whom you are giving the permissions to, such as other, by using chmod o+w testfile.txt

| improve this answer | |
  • 1
    yes, but i think +w gives permission to all( user, group and other). – Ravi Sevta Mar 10 '18 at 12:56
  • 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. – Jaken551 Mar 10 '18 at 13:00
  • if chmod a+w filename, chmod +w filename and chmod ugo+w filename are alternative to each other then why not just use +w – Ravi Sevta Mar 10 '18 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.