使用“ chmod a + x”和“ chmod 755”的区别

这可能听起来很傻,但是我有一个文件/脚本需要运行,为了做到这一点,我必须改变它成为可执行的。我想使用 chmod a+xchmod 755。但是使用 chmod a+xchmod 755有区别吗?

200292 次浏览

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.

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.

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.