What is the difference between chmod u+x
and just chmod +x
? I have seen a ton of tutorials that say to use u+x
to make scripts executable. However, omitting the u
doesn't seem to have any effect.

- 188

- 2,187
5 Answers
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 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.

- 14,355
Requirements
First of all I suggest you to read these questions and the answers linked below:
It helps you understand all the necessary parts you need to know.
Short version
chmod +x
is equal tochmod ugo+x
(Based onumask
value)chmod a+x
is equal tochmod ugo+x
(Without consideringumask
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

- 55,668
- 25
- 164
- 183
Just doing +x
will apply it to all flags: [u]ser, [g]roup, [o]thers.
Type man chmod
for more information.

- 749
-
I promise I checked the manual first but didn't see it since I skipped the description and jumped down to the options. I see them now though :-) – Nathan Schwermann Mar 08 '11 at 23:41
chmod u+x
will made the file executable for your user (it will only add it for your user, though it may be already executable by the group owner, or "other").
chmod +x
or chmod a+x
('all plus executable bit') makes the file executable by everyone.
If you do this to a directory, it makes the directory searchable, instead. I.e., you can list the contents of a directory that you have +x permission on.

- 23,120
-
@AnkitGupta I'm not sure what you're saying. My comment wasn't intended to fix a problem in a different Q&A. Try asking for clarification to answers there instead. Edit your question to say what you've tried. Show the output. – belacqua Aug 20 '12 at 19:00
chmod u+x file
means add the executable bit to the owner of the file while ignoring theumask
(Your mod will be set, no question).chmod +x file
means add the executable bit to the owner, group and others while considering theumask
(First check withumask
then apply the mods, it might have different effects based on umask's value ).
let's create two files:
$ touch file1 file2
$ ls -l file1 file2
-rw-rw-rw- 1 ravexina ravexina 0 Aug 5 01:45 file1
-rw-rw-rw- 1 ravexina ravexina 0 Aug 5 01:45 file2
Now I set the umask
to "111" to remove executable bits: umask 111
.
$ chmod u+x file1
$ chmod +x file2
$ ls -l file1 file2
-rwxrw-rw- 1 ravexina ravexina 0 Aug 5 01:47 file1
-rw-rw-rw- 1 ravexina ravexina 0 Aug 5 01:47 file2
As you can see the chmod
ignored the umask
and the file1 got executable bit for its owner however the second one did nothing because it's considering umask's value.

- 55,668
- 25
- 164
- 183
chmod +x file
different fromchmod a+x file
- see Ravexina's answer for details. – Cinnam Dec 01 '17 at 20:50