'chmod u+x' versus 'chmod +x'

The man page of chmod covers that.

  • u stands for user.
  • g stands for group.
  • o stands for others.
  • a stands for all.

That means that chmod u+x somefile will grant only the owner of that file execution permissions whereas chmod +x somefile is the same as chmod a+x somefile.

The chmod man page says:

The format of a symbolic mode is [ugoa...][[+-=][rwxXstugo...]...][,...]. Multiple symbolic operations can be given, separated by commas.

A combination of the letters 'ugoa' controls which users' access to the file will be changed: the user who owns it (u), other users in the file's group (g), other users not in the file's group (o), or all users (a). 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.


Requirements

First of all I suggest you to read these questions and the answers linked below:

  • What is the difference between “chmod +x” and “chmod 755”?
  • What is “umask” and how does it work?

It helps you understand all the necessary parts you need to know.


Short version

  • chmod +x is equal to chmod ugo+x (Based on umask value)
  • chmod a+x is equal to chmod ugo+x (Without considering umask value)

Explanation

The result of chmod a+x is to set the executable bit for everyone (Owner, Group, Others), easy right?

However with chmod +x it's a little bit tricky, it says use umask value and based on that value add the x to everyone that is allowed.

So if the umask of my environment is 0002:

$ umask
0002
$ umask -S
u=rwx,g=rwx,o=rx

It's going to add x to user (owner), group and others, in this situation (which is the default situation for most systems) it's exactly like chmod ugo+x or the same as chmod a+x, or in a more verbose form:

chmod u+x,g+x,o+x

Can you spot the connection between chmod u+x,g+x,o+x and the output of umask -S?

Now let’s change the umask of the current shell to 0003:

$ umask 0003
$ umask
0003
$ umask -S
u=rwx,g=rwx,o=r

As you can see now only owner and group are going to get the executable bit and not the others. It means chmod +x is now equal to chmod u+x,g+x or chmod ug+x.


Question time!

What happens if I run chmod +w on a file after setting umask to 0003?

Same as before, it only affects user and group of the file because 3 also removes the write permission (2).


Bonus

It has the same effect when you are removing a bit like chmod -w:

$ mkdir test
$ stat -c %A test
drwxrwxr-x
$ umask
0002
$ chmod +w test
$ stat -c %A test
drwxrwxr-x
$ chmod a+w test
$ stat -c %A test
drwxrwxrwx
$ chmod -w test
chmod: test/: new permissions are r-xr-xrwx, not r-xr-xr-x
$ stat -c %A test
dr-xr-xrwx