当前位置:网站首页>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
边栏推荐
- Cell: Tsinghua Chenggong group revealed an odor of skin flora. Volatiles promote flavivirus to infect the host and attract mosquitoes
- 关于举办科技期刊青年编辑沙龙——新时代青年编辑应具备的能力及提升策略的通知...
- 亚马逊云科技 Community Builder 申请窗口开启
- 871. Minimum refueling times
- 默认浏览器设置不了怎么办?
- 畅玩集团冲刺港股:年营收2.89亿 刘辉有53.46%投票权
- TCP congestion control details | 2 background
- Believe in yourself and finish the JVM interview this time
- IPtables中SNAT、DNAT和MASQUERADE的含义
- Flutter: 动作反馈
猜你喜欢

智能垃圾桶(五)——点亮OLED

福元医药上交所上市:市值105亿 胡柏藩身价超40亿

2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition (a sign in, B sign in, C sign in, D thinking +mst

博客主题 “Text“ 夏日清新特别版

剑指 Offer 24. 反转链表

配置基于接口的ARP表项限制和端口安全(限制用户私自接入傻瓜交换机或非法主机接入)

Fuyuan medicine is listed on the Shanghai Stock Exchange: the market value is 10.5 billion, and Hu Baifan is worth more than 4billion

DGraph: 大规模动态图数据集

Weili holdings listed on the Hong Kong Stock Exchange: with a market value of HK $500million, it contributed an IPO to Hubei

Sword finger offer 24 Reverse linked list
随机推荐
Configure ARP table entry restrictions and port security based on the interface (restrict users' private access to fool switches or illegal host access)
R and rstudio download and installation tutorial (super detailed)
[essay solicitation activity] Dear developer, RT thread community calls you to contribute
2322. 从树中删除边的最小分数(异或和&模拟)
Interpretation of key parameters in MOSFET device manual
Tech Talk 活动预告 | 基于Amazon KVS打造智能视觉产品
dstat使用[通俗易懂]
vscode设置删除行快捷键[通俗易懂]
JS delete substring in string
Flutter: 动作反馈
Experience home office, feel the completion of the project | community essay solicitation
Does digicert SSL certificate support Chinese domain name application?
Easy language ABCD sort
2、 Expansion of mock platform
2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition (a sign in, B sign in, C sign in, D thinking +mst
使用知行之桥的API端口,提供资源供合作伙伴访问
博客主题 “Text“ 夏日清新特别版
深度学习图像数据自动标注[通俗易懂]
lsf基础命令
Executive engine module of high performance data warehouse practice based on Impala