When it comes to making a file executable what is the difference between chmod 755
and chmod +x
and when would I use which? I so far have only used chmod +x
and I just read something and it used chmod 755
and I could not tell whether or not it was better to use chmod 755
or chmod +x
.
Ubuntu – the difference between “chmod +x” and “chmod 755”
chmodcommand linepermissions
Related Question
- Ubuntu – the difference between scp and cp
- Ubuntu – What’s the difference between + and = when using chmod
- Ubuntu – chmod: Everything on SD Card Stuck On 755, Owner is Root
- Ubuntu – Difference between systemctl and service commands
- Ubuntu – the main difference between chmod and chown
- Ubuntu – the difference between cat and tee
Best Answer
Short version:
To be able to compare them, we should look at them from the same perspective, so:
chmod +x
is equal tochmod ugo+x
(Based onumask
value)chmod 755
is equal tochmod u=rwx,go=rx
Explanation:
Firstly you should know that:
+
means add this permission to the other permissions that the file already has.=
means ignore all permissions, set them exactly as I provide.read = 4, write = 2, execute = 1
Here is the binary logic behind it (if you're interested):
Using
+x
you are telling to add (+
) the executable bit (x
) to the owner, group and others.ugo+x
oru+x,g+x,o+x
x
it will considers all of them. And as @Rinzwind pointed out, it's based onumask
value, it adds the bit to the onesumask
allows. remember if you specify the target likeo+r
thenumask
doesn't have any effect anymore.u+x
to only add executable bit to the owner.Using
755
you are specifying:u=rwx
(4+2+1 for owner)g=rx
(4+1 for group)o=rx
(4+1 for others)So
chmod 755
is like:chmod u=rwx,g=rx,o=rx
orchmod u=rwx,go=rx
.