当前位置:网站首页>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
边栏推荐
- vscode设置删除行快捷键[通俗易懂]
- Tech talk activity preview | building intelligent visual products based on Amazon kVs
- 相信自己,这次一把搞定JVM面试
- Ap和F107数据来源及处理
- jsp 和 servlet 有什么区别?
- Tech Talk 活动预告 | 基于Amazon KVS打造智能视觉产品
- IP地址转换地址段
- Experience home office, feel the completion of the project | community essay solicitation
- What is generics- Introduction to generics
- Sword finger offer 22 The penultimate node in the linked list
猜你喜欢
In MySQL and Oracle, the boundary and range of between and precautions when querying the date
博客主题 “Text“ 夏日清新特别版
Easy language ABCD sort
体验居家办公完成项目有感 | 社区征文
[fluent] dart data type map type (create map set | initialize map set | traverse map set)
如何与博格华纳BorgWarner通过EDI传输业务数据?
Interpretation of key parameters in MOSFET device manual
相信自己,这次一把搞定JVM面试
Eth data set download and related problems
[shutter] dart data type (dynamic data type)
随机推荐
Understand one article: four types of data index system
TCP congestion control details | 2 background
The computer comes with software to make the background color of the picture transparent (matting white background)
ThreadLocal
&lt; IV & gt; H264 decode output YUV file
Youzan won the "top 50 Chinese enterprise cloud technology service providers" together with Tencent cloud and Alibaba cloud [easy to understand]
亚马逊云科技 Community Builder 申请窗口开启
Vscode setting delete line shortcut [easy to understand]
13、Darknet YOLO3
IPtables中SNAT、DNAT和MASQUERADE的含义
Digital IC hand tearing code -- voting device
【Leetcode】14. 最長公共前綴
移动应用性能工具探索之路
P6774 [noi2020] tears in the era (block)
P6774 [NOI2020] 时代的眼泪(分块)
宝宝巴士创业板IPO被终止:曾拟募资18亿 唐光宇控制47%股权
uboot的作用和功能
Talk about an experience of job hopping and being rejected
Weili holdings listed on the Hong Kong Stock Exchange: with a market value of HK $500million, it contributed an IPO to Hubei
Jiuxian's IPO was terminated: Sequoia and Dongfang Fuhai were shareholders who had planned to raise 1billion yuan