Linux指令进阶(2)

Chown 属主及属组(更改文件以及文件夹所属的用户与所属的组)

修改某个用户、组对文件夹的属主及属组,用命令 chown 实现,案例演示如下:
(1) 修改 jfedu.net 文件夹所属的用户为 root,其中-R 参数表示递归处理所有的文件及子目录。
chown -Rroot jfedu.net
(2) 修改 jfedu.net 文件夹所属的组为 root。
chown -R:root jfedu.net 或者 chgrp –R root jfedu.net
(3) 修改 jfedu.net 文件夹所属的用户为 root,组也为 root。
chown -Rroot:root jfedu.net
[root@bogon home]# chown -R dou ./dou/* #<==把dou目录下的所有文件以及文件夹的所属用 户由root 改为dou用户
[root@bogon home]# ls -l ./dou
total48

-rw-r-xr–. 1 dou root 13 Mar 21 08:01 123.txt
-rw-r-xr–. 1 dou root 16 Mar 21 08:01 1.txt
drwxr-xr-x. 2 dou root 4096 Mar 21 08:01 Desktop
drwxr-xr-x. 2 dou root 4096 Mar 21 08:01 dfg
drwxr-xr-x. 2 dou root 4096 Mar 21 08:01 Documents
drwxr-xr-x. 2 dou root 4096 Mar 21 08:01 Downloads
drwxr-xr-x. 2 dou root 4096 Mar 21 08:01 dzqc
drwxr-xr-x. 2 dou root 4096 Mar 21 08:01 Music
drwxr-xr-x. 2 dou root 4096 Mar 21 08:01 Pictures
drwxr-xr-x. 2 dou root 4096 Mar 21 08:01 Public
drwxr-xr-x. 2 dou root 4096 Mar 21 08:01 Templates
drwxr-xr-x. 2 dou root 4096 Mar 21 08:01 Videos
[root@bogon home]# chown -R :dodo ./dou/* #<==把dou目录下所有的文件以及文件夹 所属的组改为dodo
[root@bogon home]# ls -l ./dou

total 48

-rw-r-xr–. 1 dou dodo 13 Mar 21 08:01 123.txt
-rw-r-xr–. 1 dou dodo 16 Mar 21 08:01 1.txt
drwxr-xr-x. 2 dou dodo 4096 Mar 21 08:01 Desktop
drwxr-xr-x. 2 dou dodo 4096 Mar 21 08:01 dfg
drwxr-xr-x. 2 dou dodo 4096 Mar 21 08:01 Documents
drwxr-xr-x. 2 dou dodo 4096 Mar 21 08:01 Downloads
drwxr-xr-x. 2 dou dodo 4096 Mar 21 08:01 dzqc
drwxr-xr-x. 2 dou dodo 4096 Mar 21 08:01 Music
drwxr-xr-x. 2 dou dodo 4096 Mar 21 08:01 Pictures
drwxr-xr-x. 2 dou dodo 4096 Mar 21 08:01 Public
drwxr-xr-x. 2 dou dodo 4096 Mar 21 08:01 Templates
drwxr-xr-x. 2 dou dodo 4096 Mar 21 08:01 Videos

[root@bogon
home]#

Chmod 用户及组权限

修改某个用户、组对文件夹的权限,用命令 chmod 实现,其中以代指 ugo,+、-、=代表加入、删除和等于对应权限,具体案例如下:
(1)授予用户对 jfedu.net 目录拥有 rwx 权限
chmod –R u+rwx jfedu.net
(2)授予组对 jfedu.net 目录拥有 rwx 权限
chmod –R g+rwx jfedu.net
(3)授予用户、组、其他人对 jfedu.net 目录拥有 rwx 权限
chmod –R u+rwx,g+rwx,o+rwxjfedu.net
(4)撤销用户对 jfedu.net 目录拥有 w 权限
chmod –R u-w jfedu.ne
(5)撤销用户、组、其他人对 jfedu.net 目录拥有 x 权限
chmod –R u-x,g-x,o-x jfedu.net
(6)授予用户、组、其他人对 jfedu.net 目录只有 rx 权限
chmod –R u=rx,g=rx,o=rx jfedu.net

Chmod 二进制权限

   Linux 权限默认使用 rwx 来表示,为了更简化在系统中对权限进行配置和修改,Linux权限引入二进制表示方法,如下代码:

Linux 权限可以将 rwx 用二进制来表示,其中有权限用 1 表示,没有权限用 0 表示;

Linux 权限用二进制显示如下:

rwx=111

r-x=101

rw-=110

r–=100

依次类推,转化为十进制,对应十进制结果显示如下:

rwx=111=4+2+1=7

r-x=101=4+0+1=5

rw-=110=4+4+0=6

r–=100=4+0+0=4

得出结论,用 r=4,w=2,x=1 来表示权限。

使用二进制方式来修改权限案例演示如下,其中默认
jfedu.net 目录权限为 755:

(1) 授予用户对 jfedu.net 目录拥有 rwx 权限
chmod –R 755 jfedu.net
(2) 授予组对 jfedu.net 目录拥有 rwx 权限
chmod –R 775 jfedu.net
(3) 授予用户、组、其他人对 jfedu.net 目录拥有 rwx 权限
chmod –R 777 jfedu.net
(4) 撤销用户对 jfedu.net 目录拥有 w 权限
chmod –R555 jfedu.net
(5) 撤销用户、组、其他人对 jfedu.net 目录拥有 x 权限
chmod –R644 jfedu.net
(6) 授予用户、组、其他人对 jfedu.net 目录只有 rx 权限
chmod –R 555 jfedu.n

猜你喜欢

转载自blog.csdn.net/MK750/article/details/89449644
今日推荐