5

The current file permissions look like this:

$ ls -l file
-rwxrwxr-x 1 chiranjitd chiranjitd 0 Oct 30 14:52 file

Now I try to give write permissions using chmod:

$ chmod +x+r+w file

After that, the file permissions still look like this:

$ ls -l file
-rwxrwxr-x 1 chiranjitd chiranjitd 0 Oct 30 14:52 file

The write permission is not given to the others. Why is this happening?

0

1 Answer 1

24

When you run chmod +x+r+w file, all the bits are set, except those masked by your umask. Your umask presumably masks (at least) other users’ write bit, so the +w part ends up being ignored for them.

Thus for a typical umask of 022, any chmod command which doesn’t specify who the permissions should be set for ends up ignoring any specified changes to the group’s and others’ write bits.

To set all the bits, ignoring umask, you need to specify who you want to set them for:

chmod a+rwx file

or more explicitly,

chmod ugo+rwx file

(or any subset of ugo, as appropriate, for the user, group, and/or others).

It’s also possible to specify numeric permissions instead of symbolic permissions; see Understanding UNIX permissions and file types for details.

Note that the umask masking behaviour also applies when clearing bits, which can produce surprising results: chmod -w file will only clear write bits which would be set by chmod +w file! Continuing with a typical umask of 022, this means that chmod -w won’t touch the group’s or others’ write bits, leaving them set if they already are. (GNU coreutilschmod helpfully warns about this.)

7
  • 7
    oh, that last part is indeed surprising. Looks like GNU coreutils' chmod warns about that: chmod 777 test.txt; chmod -w test.txt gives chmod: test.txt: new permissions are r-xrwxrwx, not r-xr-xr-x Commented Oct 30, 2021 at 17:20
  • Let's not forget that once the file permission assignment is correct, the user must also have the ability to "see into" the directory (ie: ls returns the file listing) in addition to read/write the file itself. Commented Oct 31, 2021 at 0:02
  • @IanW that's not exactly true, they only need the right to traverse the directory (ie. x), not to list its content (ie. r). Commented Oct 31, 2021 at 7:50
  • @ginnungagap, just saying it's not just the file perms, it's also got to do with the directory settings. The respondent should add that for a complete answer, per your details, yes. Commented Oct 31, 2021 at 10:45
  • 1
    @IanW that aspect doesn’t come into play here, as indicated by the OP’s initial ls -l (which wouldn’t work correctly if the OP couldn’t read and traverse the current directory). I prefer to keep answers focused on the problem at hand, rather than attempting to address all possible areas of misunderstanding. Commented Oct 31, 2021 at 20:18

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.