频道栏目
首页 > 资讯 > 其他 > 正文

十、修改权限命令-12926780-51CTO博客

20-05-14        来源:[db:作者]  
收藏   我要投稿
前言

如何对一个文件/目录的权限进行管理呢? Linux/Unix 的文件调用权限分为三级 : 文件拥有者、群组、其他。chmod用于管理文件或目录的权限,文件或目录权限的控制分别以读取(r)、写入(w)、执行(x)3种来表示可读可写可执行。

修改权限命令

chmod 修改文件、目录权限

chomd u+x/tmp/testfile chomd 755 /tmp/testfile

chown 更改属主、属组

chgrp 可以单独更改属组,不常用

权限范围

权限范围:u,User    即文件或目录的拥有者g,Group   即文件或目录的所属群组o,Other    除了文件或目录拥有者或所属群组之外,其他用户皆属于这个范围a,All     即全部的用户,包含拥有者,所属群组以及其他用户

练习

1 给a.txt文件的拥有者赋予可执行权限

@SC02ZRC4KMD6N ~ % ls -l a.txt
-rw-r--r--  1 user1  staff  14  3 29 14:43 a.txt
user1@SC02ZRC4KMD6N ~ % chmod u+x a.txt
user1@SC02ZRC4KMD6N ~ % ls -l a.txt    
-rwxr--r--  1 user1  staff  14  3 29 14:43 a.txt

2 给属组减少可读权限

user1@SC02ZRC4KMD6N ~ % chmod g-r a.txt
user1@SC02ZRC4KMD6N ~ % ls -l a.txt    
-rwx---r--  1 user1  staff  14  3 29 14:43 a.txt

3 给其他用户设置只有只写权限

user1@SC02ZRC4KMD6N ~ % chmod o=w a.txt
user1@SC02ZRC4KMD6N ~ % ls -l a.txt    
-rwx----w-  1 user1  staff  14  3 29 14:43 a.txt

4 给所有用户增加可读权限

user1@SC02ZRC4KMD6N ~ % chmod a+r a.txt
user1@SC02ZRC4KMD6N ~ % ls -l a.txt    
-rwxr--rw-  1 user1  staff  14  3 29 14:43 a.txt

5 用数字给其他用户设置读写权限,自己和属组为只读权限

user1@SC02ZRC4KMD6N ~ % chmod 446 a.txt 
user1@SC02ZRC4KMD6N ~ % ls -l a.txt    
-r--r--rw-  1 user1  staff  14  3 29 14:43 a.txt

6 创建一个文件的默认权限为666减去umask值

user1@SC02ZRC4KMD6N ~ % touch e.txt
user1@SC02ZRC4KMD6N ~ % ls -l e.txt
-rw-r--r--  1 user1  staff  0  3 29 18:15 e.txt
user1@SC02ZRC4KMD6N ~ % umask
022
相关TAG标签
上一篇:gps位置模拟器在的使用价值-wx5c55329eab678的博客-51CTO博客
下一篇:Patch Tuesday解决了Microsoft的115个CVE和Firefox的12个CVE-运维小能手的博客-51CTO博客
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站