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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 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).
+rmeansugo+rbecause002 & 444is000, which lets all bits to be set+xmeansugo+xbecause002 & 111is000, which lets all bits to be set- but
+wmeansug+wbecause002 & 222is002, which prevents the “o” bit to be set.
Other examples
- With
umask 022+wwould meanu+w. - With
umask 007+rwxwould meanug+rwx. - With
umask 077+rwxwould 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).
Method 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>
Method 3
You need to specify to whom you are giving the permissions to, such as other, by using chmod o+w testfile.txt
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0