免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1004 | 回复: 0
打印 上一主题 下一主题

Linux文件属性、权限设置 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-10-24 16:14 |只看该作者 |倒序浏览
Linux文件属性、权限设置文件属性和权限
[color="#ffffff"][root@daf root]# ls -al
[color="#ffffff"]total 64
[color="#ffffff"]drwxr-x---    4 root     root         4096 Feb 14 22:02 .
[color="#ffffff"]drwxr-xr-x   23 root     root         4096 Feb 16 13:35 ..
[color="#ffffff"]-rw-r--r--    1 root     root         1210 Feb 10 06:03 anaconda-ks.cfg
[color="#ffffff"]-rw-------    1 root     root        12447 Feb 14 23:22 .bash_history
[color="#ffffff"]-rw-r--r--    1 root     root           24 Jun 11  2000 .bash_logout
[color="#ffffff"]-rw-r--r--    1 root     root          234 Jul  6  2001 .bash_profile
[color="#ffffff"]-rw-r--r--    1 root     root          217 Feb  9 22:06 .bashrc
[color="#ffffff"]-rw-r--r--    1 root     root          210 Jun 11  2000 .cshrc
[color="#ffffff"]drwx------    2 root     root         4096 Feb 14 21:54 .gnupg
[color="#ffffff"]-rw-------    1 root     root            8 Feb 14 22:05 .mysql_history
[color="#ffffff"]drwx------    2 root     root         4096 Feb 10 00:44 .ssh
[color="#ffffff"]-rw-r--r--    1 root     root          196 Jul 11  2000 .tcshrc
[color="#ffffff"]-rw-r--r--    1 root     root         1126 Aug 24  1995 .Xresources
[color="#ffff00"]     一      二   三     四           五   六           七
[color="#ffff00"][文件属性][节点数][作者][所属群组]   [大小][创建时间]   [文件名]
*文件名中带有[ . ]开头的代表隐藏文件。



文件类型代码:[ d ]--目录、[ - ]--文件、[ l ]--链接、[ b ]--可储存周边设备、[ c ]--序列设备。

文件权限属性:[ r ]--可读、[ w ]--可写、[ x ]--可执行。
*对于目录,必需具有执行权限才可进入
*文件的执行属性将决定文件是否可执行,而与文件扩展名无关

改变权限设置:
chgrp :改变所属群组
*要改变的群組名必须在 /etc/group 中存在
 
[color="#ffffcc"]语法:
[color="#ffff00"]chgrp 群组名 文件或目录
[color="#ffffcc"]如:
[color="#ffffff"][root@test root]# [color="#ffff00"]chgrp users tmp
[color="#ffffff"][root@test root]# [color="#ffff00"]ls –l
[color="#ffffff"]drwx------    2 root     root         4096 Oct 19 11:43 drakx/
[color="#ffffff"]drwx------    2 root     users        4096 Oct 19 21:24 tmp/
[color="#ffffff"][root@test root]# [color="#ffff00"]chgrp testing tmp
[color="#ffffff"]chgrp: invalid group name `testing'   [color="#ff9900"]
chown :改变作者
[ -R ] :同时对目录下的所有子目录或文件的作者进行修改
*用户名必须已存在系统中,也就是在 /etc/passwd 中存在的用户名。
*chown 可直接修改所属群組
 
[color="#ffffcc"]语法:
[color="#ffff00"]chown [ -R ] 用户名 文件或目录
[color="#ffff00"]chown [ -R ] 用户名:群组名 文件或目录
[color="#ffffcc"]如:
[color="#ffffff"][root@test root]# [color="#ffff00"]chown test tmp
[color="#ffffff"][root@test root]# [color="#ffff00"]ls -l
[color="#ffffff"]total 28
[color="#ffffff"]drwx------    2 root     root         4096 Oct 19 11:43 drakx/
[color="#ffffff"]drwx------    2 test     users        4096 Oct 19 21:24 tmp/
[color="#ffffff"][root@test root]# [color="#ffff00"]chown –R root:root tmp
[color="#ffffff"][root@test root]# [color="#ffff00"]ls –l
[color="#ffffff"]drwx------    2 root     root         4096 Oct 19 11:43 drakx/
[color="#ffffff"]drwx------    2 root     root         4096 Oct 19 21:24 tmp/
 
chmod :改变权限属性
方式一 数字类型改变
三个基本属性:r、w、x的数字类型代表:r:4、w:2 、x:1
[color="#ffffff"]语法:
[color="#ffff00"]chmod [-R] xyz 文件或目录
[color="#ff9900"]xyz 为三組 rwx 属性数值的相加
[color="#ff9900"]同一组的数字是相加!如属性为 [ -rwxrwx--- ] ,则:
owner  = rwx  = 4+2+1 = 7
group  = rwx  = 4+2+1 = 7
others = ---  = 0+0+0 = 0
[color="#ffffff"][root@test root]# [color="#ffff00"]ls –al .bashrc
[color="#ffffff"]-rw-r--r--    1 root     root          226 Feb 16  2002 .bashrc
[color="#ffffff"][root@test root]# [color="#ffff00"]chmod 777 .bashrc
[color="#ffffff"][root@test root]# [color="#ffff00"]ls –al .bashrc
[color="#ffffff"]-rwxrwxrwx    1 root     root          226 Feb 16  2002 .bashrc
 
方式二 符号类型改变
九个属性分別代表是(1)user (2)group (3)others 三个群组的权限,可以由 u, g, o 來代表三个群组!而 a 则代表 all 亦即全部。

chmod
u
g
o
a
+(加入)
-(除去)
=(设定)
r
w
x
文件或目录[color="#ffffff"] 
 
[color="#ffffff"][root@test root]# [color="#ffff00"]chmod u=rwx,og=rx .bashrc
[color="#ffffff"][root@test root]# [color="#ffff00"]ls –al .bashrc
[color="#ffffff"]-rwxr-xr-x    1 root     root          226 Feb 16  2002 .bashrc
[color="#ffffff"][root@test root]# ls –al .bashrc
[color="#ffffff"]-rwxr-xr-x    1 root     root          226 Feb 16  2002 .bashrc
[color="#ffffff"][root@test root]# [color="#ffff00"]chmod a+w .bashrc
[color="#ffffff"][root@test root]# [color="#ffff00"]ls –al .bashrc
[color="#ffffff"]-rwxrwxrwx    1 root     root          226 Feb 16  2002 .bashrc
[color="#ffffff"][root@test root]# [color="#ffff00"]chmod a-x .bashrc
[color="#ffffff"][root@test root]# [color="#ffff00"]ls –al .bashrc
[color="#ffffff"]-rw-rw-rw-    1 root     root          226 Feb 16  2002 .bashrc
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/51777/showart_1334524.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP