程序员

“chmod 666” 什么意思?

2019-04-22  本文已影响1人  世外大帝

今天看android源码中的串口部分,有一个命令是chmod 666 ,之前知道777是全部授权,666用的还真不多

/* Missing read/write permission, trying to chmod the file */
Process su;
su = Runtime.getRuntime().exec("/system/bin/su");
String cmd = "chmod 666 " + device.getAbsolutePath() + "\n"
        + "exit\n";
su.getOutputStream().write(cmd.getBytes());
if ((su.waitFor() != 0) || !device.canRead()
        || !device.canWrite()) {
    new AlertDialog.Builder(Sercd.this)
        .setMessage(R.string.su_failed)
        .show();
    return false;
}

查询结果如下:

chmod 命令更改文件/文件夹的属性:

permission to:  user(u)   group(g)   other(o)     
                /¯¯¯\      /¯¯¯\      /¯¯¯\
octal:            6          6          6
binary:         1 1 0      1 1 0      1 1 0
what to permit: r w x      r w x      r w x

binary         - 1: enabled, 0: disabled

what to permit - r: read, w: write, x: execute

permission to  - user: the owner that create the file/folder
                 group: the users from group that owner is member
                 other: all other users

或者,你可以通过一个更直观的语法执行命令,不需要去考虑二进制或八进制(但数字语法的知识还是重要的):chmod u=rw, g=rw, o=rw file/folder

记住,通过 chmod 命令改变权限需要至少3个参数,因此在没有显式文件/文件夹的情况下, chmod 666 啥都不做。

另外,如果不会引起不稳定的问题,或只是无用权限变更,也一定要进行批评,因为 chmod 666 将允许文件/文件夹写为所有,而执行为none。

翻译自 https://superuser.com/questions/295591/what-is-the-meaning-of-chmod-666

上一篇下一篇

猜你喜欢

热点阅读