“chmod 666” 什么意思?

今天看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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值