当前位置:网站首页>chmod命令原理及用法详解[通俗易懂]
chmod命令原理及用法详解[通俗易懂]
2022-07-02 14:42:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
Chmod命令主要用于修改、设置文件权限
chmod 修改文件权限主要有两种方式: 字母法与数字法
虽然数字法相对字母法简单,但是数字法是基于字母法,所以这里先介绍字母法。
1、字母法:chmod (u g o a) (+ – =) (r w x) (文件名)
以上是chmod的用法,每个括号是一个参数, 前三个括号主要放在一起使用即 chmod + 设置模式 + 文件名;下面先介绍这些参数的意义:
[u g o a] | 含义 |
---|---|
u | user 表示该文件的所有者 |
g | group 表示与该文件的所有者属于同一组( group )者,即用户组 |
o | other 表示其它用户组 |
a | all 表示这三者皆是 |
[+ – =] | 含义 |
---|---|
+ | 增加权限 |
– | 撤销权限 |
= | 设定权限 |
[r w x] | 含义 |
---|---|
r | read 表示可读取,对于一个目录,如果没有r权限,那么就意味着不能通过ls查看这个目录的内容。 |
w | write 表示可写入,对于一个目录,如果没有w权限,那么就意味着不能在目录下创建新的文件。 |
x | excute 表示可执行,对于一个目录,如果没有x权限,那么就意味着不能通过cd进入这个目录。 |
用法:chmod + 设置模式 + 文件名 中间的设置模式,要分别对u(user), g(group), o(other)设置权限。
chmod u+rwx, g+rwx, o+rwx filename 改命令说明对filename文件, 赋予user、group、other均有read、write、excute的权限
所以设置模式中应该包含对三种用户类型的权限设置,各自独立,互不影响。
举例说明:
chmod u+rw filename 说明对于filname, 只赋予user用户, read、write权限
chmod u+rwx, g+rw filename 说明对filename,赋予user用户read、write、excute权限;赋予group用户read、write权限
注意:(chmod + 设置模式 + 文件名) 设置模式中包含对三种类型用户(u、g、o)的权限设置,这三者各自独立,互不干扰。
2、数字法
数字法是基于字母法的表示,如果字母法懂了,数字法就好懂,并且易于使用。
用法:chmod + 数字组合 + 文件名 数字组合一般包含三个数字:
第一个数字对应字母法的用户u(user)
第二个数字对应字母法的用户g(group)
第三个数字对应字母法的用户o(other)
另外:
r (read) —————-> 4
w (write) —————-> 2
x (excute) —————-> 1
示例详解:
数字法:chmod 777 文件名 <———–对应————–> 字母法: chmod u+rwx, g+rwx, o+rwx 文件名
第一个数字7:代表用户 u 的权限 rwx, 4 (r) + 2 (w) + 1 (x) = 7
第二个数字7:代表用户 g 的权限 rwx, 4 (r) + 2 (w) + 1 (x) = 7
第三个数字7:代表用户 o 的权限 rwx, 4 (r) + 2 (w) + 1 (x) = 7
举例说明:
数字法:chmod 755 filename 对应 字母法: chmod u+rwx, g+rx, o+rx filename
数字法:chmod 751 filename 对应 字母法: chmod u+rwx, g+rx, o+x filename
数字法:chmod 765 filename 对应 字母法: chmod u+rwx, g+rw, o+rx filename
经过以上介绍,应该对于chmod的用法明白了。
附录 —— chmod 数字法另一种解释: 刚才上面的解释是基于求和的方法,下面用二进制的方法进行解释数字法表示: r w x 权限用用三位二进制数字表示: 第一位数字(0或1)表示 r, 为1表示有效, 0无效 第二位数字 (0或1) 表示 w, 为1表示有效,0无效 第三位数字 (0或1) 表示 x, 为1表示有效, 0无效 000 <———————> 无任何权限 100 <———————> r(read) <—–> 4 010 <———————> w(write) <—–> 2 001 <———————-> x(excute) <—-> 1 101 <———————-> rx <—-> 5 110 <———————-> rw <—-> 6 111 <———————-> rwx <—–> 7
参考资料: http://www.cnblogs.com/loaderman/p/6547609.htmlhttp://blog.csdn.net/leilu2008/article/details/8507037http://blog.chinaunix.net/uid-21880738-id-1813031.htmlhttp://www.cnblogs.com/chengJAVA/p/4319420.htmlhttps://zhidao.baidu.com/question/168415347.html
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/148020.html原文链接:https://javaforall.cn
边栏推荐
- Learning Weekly - total issue 60 - 25th week of 2022
- 【征文活动】亲爱的开发者,RT-Thread社区喊你投稿啦
- Configure ARP table entry restrictions and port security based on the interface (restrict users' private access to fool switches or illegal host access)
- Sword finger offer 26 Substructure of tree
- ThreadLocal
- Tech Talk 活动预告 | 基于Amazon KVS打造智能视觉产品
- Eth data set download and related problems
- Nexus简介及小白使用IDEA打包上传到Nexus3私服详细教程
- 一文看懂:数据指标体系的4大类型
- 2322. Remove the minimum fraction of edges from the tree (XOR and & Simulation)
猜你喜欢
In MySQL and Oracle, the boundary and range of between and precautions when querying the date
Does digicert SSL certificate support Chinese domain name application?
[leetcode] 14. Préfixe public le plus long
Tech talk activity preview | building intelligent visual products based on Amazon kVs
[cloud native] briefly talk about the understanding of flume, a massive data collection component
AP and F107 data sources and processing
Green bamboo biological sprint Hong Kong stocks: loss of more than 500million during the year, tiger medicine and Beijing Yizhuang are shareholders
GeoServer:发布PostGIS数据源
剑指 Offer 26. 树的子结构
Cell:清华程功组揭示皮肤菌群的一种气味挥发物促进黄病毒感染宿主吸引蚊虫...
随机推荐
福元医药上交所上市:市值105亿 胡柏藩身价超40亿
class和getClass()的区别
System Verilog implements priority arbiter
Sword finger offer 25 Merge two sorted linked lists
上传代码到远程仓库报错error: remote origin already exists.
LSF basic command
C语言自定义函数的方法
入行数字IC验证后会做些什么?
学习周刊-总第60期-2022年第25周
博客主题 “Text“ 夏日清新特别版
Error when uploading code to remote warehouse: remote origin already exists
配置基于接口的ARP表项限制和端口安全(限制用户私自接入傻瓜交换机或非法主机接入)
ssb门限_SSB调制「建议收藏」
ThreadLocal
Timing / counter of 32 and 51 single chip microcomputer
Weili holdings listed on the Hong Kong Stock Exchange: with a market value of HK $500million, it contributed an IPO to Hubei
Experience home office, feel the completion of the project | community essay solicitation
In MySQL and Oracle, the boundary and range of between and precautions when querying the date
Executive engine module of high performance data warehouse practice based on Impala
Nexus简介及小白使用IDEA打包上传到Nexus3私服详细教程