美文网首页程序员
“chmod 666” 什么意思?

“chmod 666” 什么意思?

作者: 世外大帝 | 来源:发表于2019-04-22 15:00 被阅读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 命令更改文件/文件夹的属性:

    • chmod 666 file/folder 表示所有用户都可以读写但不能执行文件/文件夹;
    • chmod 777 file/folder 允许所有用户的所有操作(一般的暴力解决办法)
    • chmod 744 file/folder 只允许用户(所有者)执行所有操作;组和其他用户只允许阅读。
    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

    相关文章

      网友评论

        本文标题:“chmod 666” 什么意思?

        本文链接:https://www.haomeiwen.com/subject/etwygqtx.html