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.
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.
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.
chmod +xis equal to
chmod ugo+x(Based on
chmod a+xis equal to
chmod ugo+x(Without considering
The result of
chmod a+x is to set the executable bit for everyone (Owner, Group, Others), easy right?
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
$ 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:
Can you spot the connection between
chmod u+x,g+x,o+x and the output of
Now let’s change the
umask of the current shell to
$ 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
What happens if I run
chmod +w on a file after setting
Same as before, it only affects
group of the file because 3 also removes the write permission (2).
It has the same effect when you are removing a bit like
$ 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
+x will apply it to all flags: [u]ser, [g]roup, [o]thers.
man chmod for more information.
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.
chmod u+x filemeans add the executable bit to the owner of the file while ignoring the
umask(Your mod will be set, no question).
chmod +x filemeans add the executable bit to the owner, group and others while considering the
umask(First check with
umaskthen 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:
$ 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.