This may sound silly, but I have a file/ script that need to run and in order to do it I must change it to become executable. I would want to use either chmod a+x or chmod 755. But is there a difference between using chmod a+x and chmod 755?
Asked
Active
Viewed 2.1e+01k times
92
user2579439
- 1,193
- 3
- 13
- 13
-
9chmod is short for change mode. chmod [references][operator][modes] file a+x meaning is a -> all(owner,group and other) – Neha Gangwar Sep 26 '17 at 06:18
3 Answers
101
chmod a+x modifies the argument's mode while chmod 755 sets it. Try both variants on something that has full or no permissions and you will notice the difference.
filmor
- 30,840
- 6
- 50
- 48
-
14
-
ls -llh tempfile --> -rwerwerwe ............. chmod 755 tempfile --> -rwer-er-e .......... But chmod a+x tempfile --> -rwerwerwe – Mohsen Abasi Oct 05 '20 at 09:11
-
1In other words, `chmod a+x` reads the permissions, and then writes, whereas `chmod 755` only writes. – Sapphire_Brick Oct 23 '20 at 03:09
83
Yes - different
chmod a+x will add the exec bits to the file but will not touch other bits. For example file might be still unreadable to others and group.
chmod 755 will always make the file with perms 755 no matter what initial permissions were.
This may or may not matter for your script.
akostadinov
- 17,364
- 6
- 77
- 85
46
Indeed there is.
chmod a+x is relative to the current state and just sets the x flag. So a 640 file becomes 751 (or 750?), a 644 file becomes 755.
chmod 755, however, sets the mask as written: rwxr-xr-x, no matter how it was before. It is equivalent to chmod u=rwx,go=rx.
glglgl
- 89,107
- 13
- 149
- 217