Linux – Removing and adding permission using numerical notation on the same line

chmodlinux

I'm having some trouble trying to remove write permission from the owning group (g), and to add read permission to others (o) at the same time.

How would I remove some permission from the owning group and add some permission for others in the same line?

Best Answer

Noting the title of your question:

Removing and adding permission using numerical notation on the same line

With chmod from GNU coreutils, which you probably have on a Linux system, you could use

$ chmod -020,+004 test.txt

to do that. It works in the obvious way: middle digit for the group, 2 is for write; and last digit for "others", and 4 for read.

Being able to use + or - with a numerical mode is a GNU extension, e.g. the BSD-based chmod on my Mac gives an error for +004:

$ chmod +004 test.txt
chmod: Invalid file mode: +004

So it would be simpler, shorter, more portable and probably more readable to just use the symbolic form:

$ chmod g-w,o+r test.txt
Related Question