当前位置:网站首页>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
边栏推荐
- 2322. Remove the minimum fraction of edges from the tree (XOR and & Simulation)
- Un an à dix ans
- MOSFET器件手册关键参数解读
- Fuyuan medicine is listed on the Shanghai Stock Exchange: the market value is 10.5 billion, and Hu Baifan is worth more than 4billion
- In MySQL and Oracle, the boundary and range of between and precautions when querying the date
- 剑指 Offer 26. 树的子结构
- 深度之眼(三)——矩阵的行列式
- Sword finger offer 27 Image of binary tree
- 入行数字IC验证后会做些什么?
- Use of openpose
猜你喜欢
13、Darknet YOLO3
綠竹生物沖刺港股:年期內虧損超5億 泰格醫藥與北京亦莊是股東
使用知行之桥的API端口,提供资源供合作伙伴访问
[fluent] dart data type map type (create map set | initialize map set | traverse map set)
Just a coincidence? The mysterious technology of apple ios16 is even consistent with the products of Chinese enterprises five years ago!
智能垃圾桶(五)——点亮OLED
ETH数据集下载及相关问题
ThreadLocal
Tech talk activity preview | building intelligent visual products based on Amazon kVs
Green bamboo biological sprint Hong Kong stocks: loss of more than 500million during the year, tiger medicine and Beijing Yizhuang are shareholders
随机推荐
Understand one article: four types of data index system
[cloud native] briefly talk about the understanding of flume, a massive data collection component
Tech talk activity preview | building intelligent visual products based on Amazon kVs
Un an à dix ans
Cell:清华程功组揭示皮肤菌群的一种气味挥发物促进黄病毒感染宿主吸引蚊虫...
Ap和F107数据来源及处理
社交元宇宙平台Soul冲刺港股:年营收12.8亿 腾讯是股东
QStyle实现自绘界面项目实战(二)
体验居家办公完成项目有感 | 社区征文
Shutter: action feedback
Interpretation of key parameters in MOSFET device manual
Use of openpose
酒仙网IPO被终止:曾拟募资10亿 红杉与东方富海是股东
Changwan group rushed to Hong Kong stocks: the annual revenue was 289million, and Liu Hui had 53.46% voting rights
一文看懂:数据指标体系的4大类型
How to transfer business data with BorgWarner through EDI?
OpenPose的使用
剑指 Offer 22. 链表中倒数第k个节点
System Verilog implements priority arbiter
P6774 [noi2020] tears in the era (block)