Difference between using "chmod a+x" and "chmod 755"

LinuxUnixChmod

Linux Problem Overview


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?

Linux Solutions


Solution 1 - Linux

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.

Solution 2 - Linux

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.

Solution 3 - Linux

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser2579439View Question on Stackoverflow
Solution 1 - LinuxfilmorView Answer on Stackoverflow
Solution 2 - LinuxakostadinovView Answer on Stackoverflow
Solution 3 - LinuxglglglView Answer on Stackoverflow