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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18596778/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 00:43:55  来源:igfitidea点击:

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

linuxunixchmod

提问by user2579439

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+xor chmod 755. But is there a difference between using chmod a+xand chmod 755?

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

采纳答案by filmor

chmod a+xmodifiesthe argument's mode while chmod 755setsit. Try both variants on something that has full or no permissions and you will notice the difference.

chmod a+xchmod 755设置参数时修改参数的模式。在具有完全权限或没有权限的内容上尝试这两种变体,您会注意到不同之处。

回答by akostadinov

Yes - different

是 - 不同

chmod a+xwill add the exec bits to the file but will not touch other bits. For example file might be still unreadable to othersand group.

chmod a+x将 exec 位添加到文件中,但不会触及其他位。例如,文件可能仍然无法读取othersgroup

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

chmod 755755无论初始权限是什么,都将始终使用权限创建文件。

This may or may not matter for your script.

这对您的脚本可能重要也可能无关紧要。

回答by glglgl

Indeed there is.

确实有。

chmod a+xis relative to the current state and just sets the xflag. 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