当前位置:网站首页>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
边栏推荐
- Chapter 3 of hands on deep learning - (1) linear regression is realized from scratch_ Learning thinking and exercise answers
- The poor family once again gave birth to a noble son: Jiangxi poor county got the provincial number one, what did you do right?
- Weili holdings listed on the Hong Kong Stock Exchange: with a market value of HK $500million, it contributed an IPO to Hubei
- Understand one article: four types of data index system
- Learning Weekly - total issue 60 - 25th week of 2022
- 福元医药上交所上市:市值105亿 胡柏藩身价超40亿
- 剑指 Offer 27. 二叉树的镜像
- IPtables中SNAT、DNAT和MASQUERADE的含义
- 几行代码搞定RPC服务注册和发现
- QStyle实现自绘界面项目实战(二)
猜你喜欢

MOSFET器件手册关键参数解读

DGraph: 大规模动态图数据集

Changwan group rushed to Hong Kong stocks: the annual revenue was 289million, and Liu Hui had 53.46% voting rights

In MySQL and Oracle, the boundary and range of between and precautions when querying the date

A few lines of code to complete RPC service registration and discovery

【Leetcode】14. Longest Common Prefix

Executive engine module of high performance data warehouse practice based on Impala

超卓航科上市:募资9亿市值超60亿 成襄阳首家科创板企业

Ap和F107数据来源及处理

Qwebengineview crash and alternatives
随机推荐
Configure ARP table entry restrictions and port security based on the interface (restrict users' private access to fool switches or illegal host access)
Xiaopeng P7 had an accident on rainy days, and the airbag did not pop up. Official response: the impact strength did not meet the ejection requirements
Linux Installation PostgreSQL + Patroni cluster problem
人生的开始
Sword finger offer 26 Substructure of tree
Sword finger offer 21 Adjust the array order so that odd numbers precede even numbers
有赞和腾讯云、阿里云一同摘得“中国企业云科技服务商50强”[通俗易懂]
Win10系统使用pip安装juypter notebook过程记录(安装在系统盘以外的盘)
System Verilog implements priority arbiter
The poor family once again gave birth to a noble son: Jiangxi poor county got the provincial number one, what did you do right?
配置基于接口的ARP表项限制和端口安全(限制用户私自接入傻瓜交换机或非法主机接入)
LSF basic command
OpenHarmony如何启动远程设备的FA
IPtables中SNAT、DNAT和MASQUERADE的含义
What is the difference between JSP and servlet?
Error when uploading code to remote warehouse: remote origin already exists
Digital IC hand tearing code -- voting device
QStyle实现自绘界面项目实战(二)
A case study of college entrance examination prediction based on multivariate time series
[fluent] dart data type map type (create map set | initialize map set | traverse map set)