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

时间:2021-08-31 16:42:24

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?

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

3 个解决方案

#1


49  

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.

chmod a+x修改参数的模式,而chmod 755设置。尝试两个变量都有完全或没有权限,您将注意到差异。

#2


30  

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 a+x将把exec位添加到文件中,但不会触及其他位。例如,文件可能仍然不能读给其他人和组。

chmod 755 will always make the file with perms 755 no matter what initial permissions were.

无论初始权限是什么,chmod 755总是会使文件具有perm755。

This may or may not matter for your script.

这可能对您的脚本很重要。

#3


19  

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 a+x相对于当前状态,只设置x标志。所以640个文件变成751(或750?),644个文件变成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.

然而,chmod 755却设置了这样的掩码:rwxr-xr-x,不管它以前是什么样子。它等于chmod u=rwx,go=rx。

#1


49  

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.

chmod a+x修改参数的模式,而chmod 755设置。尝试两个变量都有完全或没有权限,您将注意到差异。

#2


30  

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 a+x将把exec位添加到文件中,但不会触及其他位。例如,文件可能仍然不能读给其他人和组。

chmod 755 will always make the file with perms 755 no matter what initial permissions were.

无论初始权限是什么,chmod 755总是会使文件具有perm755。

This may or may not matter for your script.

这可能对您的脚本很重要。

#3


19  

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 a+x相对于当前状态,只设置x标志。所以640个文件变成751(或750?),644个文件变成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.

然而,chmod 755却设置了这样的掩码:rwxr-xr-x,不管它以前是什么样子。它等于chmod u=rwx,go=rx。