目录
一、查看权限信息
通过ls命令可以查看权限信息
ls -l [Linux路径]
- Block1,表示文件、文件夹的权限控制信息
- Block2,表示文件、文件夹所属用户
- Block3,表示文件、文件夹所属用户组
例 在上图中,文件test的所属用户为centoswxx,所属用户组为centoswxx
二、权限控制信息
权限共有r、w、x三种
- r权限:读权限。对于文件,查看文件内容;对于文件夹,查看文件夹内容
- w权限:写权限。对于文件,修改文件;对于文件夹,对文件夹进行创建、删除、改名等操作
- x权限:执行权限。对于文件,将文件作为程序执行;对于文件夹,可以更改工作目录到此文件夹,即cd命令
Block1中的权限控制信息总共有10个槽位
- Group1 ,表示这是一个文件(-)或文件夹(d)或软链接(l)
- Group2,表示所属用户权限,若显示-,则表示没有该种权限
- Group3,表示所属用户组权限,若显示-,则表示没有该种权限
- Group4,表示其他用户权限,其他用户是指非所属用户且不在所属用户组中的用户,若显示-,则表示没有该种权限
例:drwxr-xr-x
首字母d,表示这是一个文件夹
所属用户(Block2)对该文件夹有r权限、有w权限、有x权限
所属用户组(Block3)对该文件夹有r权限、没有w权限、有x权限
其他用户(非所属用户且不在所属用户组中的用户)对该文件夹有r权限、没有w权限、有x权限
三、相关命令
1.chmod命令
chmod [-R] 权限 文件或文件夹
作用:修改文件/文件夹的权限信息
但是,只有文件 /文件夹的所属用户或root用户可以修改
-R,表示对文件夹及其内部的全部内容进行权限信息修改
parameter“权限”的表示方法:
1.字母表示
u= ,g= ,o= //如u=rwx,g=rx,o=x
其中,u表示user所属用户,g表示group所属用户组,o表示other其他用户
2.数字表示
其中,num1为表示用户权限的数字,num2为表示用户组权限的数字,num3为表示其他用户权限的数字num1num2num3 //如311表示-wx--x--x
数字(十进制) 权限 对应的二进制(便于理解记忆) 0 --- 000 1 --x 001 2 -w- 010 3 -wx 011 4 r-- 100 5 r-x 101 6 rw- 110 7 rwx 111
不添加option
[centoswxx@localhost ~]$ ls -l total 4 drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Desktop drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Documents drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Downloads drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Music drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Pictures drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Public drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Templates -rw-rw-r--. 1 centoswxx centoswxx 131 Mar 11 05:50 test //文件test的权限信息为rw-rw-r-- drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Videos [centoswxx@localhost ~]$ chmod u=rwx,g=rx,o=x test [centoswxx@localhost ~]$ ls -l total 4 drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Desktop drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Documents drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Downloads drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Music drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Pictures drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Public drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Templates -rwxr-x--x. 1 centoswxx centoswxx 131 Mar 11 05:50 test //文件test的权限信被修改为rwxr-x--x drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Videos
添加-R
[centoswxx@localhost ~]$ ls -l total 4 drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Desktop drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Documents drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Downloads drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Music drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Pictures drwxrwxr-x. 2 centoswxx centoswxx 6 Mar 11 23:56 POI //文件夹POI的权限为rwxrwxr-x drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Public drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Templates -rwxr-x-wx. 1 centoswxx centoswxx 131 Mar 11 05:50 test drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Videos [centoswxx@localhost ~]$ cd POI //进入文件夹POI [centoswxx@localhost POI]$ touch Name //在文件夹POI中创建文件Name [centoswxx@localhost POI]$ ls -l total 0 -rw-rw-r--. 1 centoswxx centoswxx 0 Mar 11 23:59 Name //文件Name的权限为rw-rw-r-- [centoswxx@localhost ~]$ chmod -R u=rwx,g=rwx,o=rwx POI //将文件夹POI及其内部全部内容的权限都修改为rwxrwxrwx [centoswxx@localhost ~]$ ls -l total 4 drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Desktop drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Documents drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Downloads drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Music drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Pictures drwxrwxrwx. 2 centoswxx centoswxx 18 Mar 11 23:59 POI //文件夹POI的权限被修改为rwxrwxrwx drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Public drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Templates -rwxr-x-wx. 1 centoswxx centoswxx 131 Mar 11 05:50 test drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Videos [centoswxx@localhost ~]$ cd POI [centoswxx@localhost POI]$ ls -l total 0 -rwxrwxrwx. 1 centoswxx centoswxx 0 Mar 11 23:59 Name //文件夹POI中的文件Name的权限也被修改为rwxrwxrwx
2.chown命令
chown [-R] [用户][:][用户组] 文件或文件夹
作用:修改文件/文件夹的所属用户和所属用户组
但是,只有root用户有权利执行chown命令
-R,表示对文件夹及其内部的全部内容进行所属用户和所属用户组的修改
:,用于分隔用户和用户组
不添加option
[root@localhost ~]# cd /home/centoswxx/ [root@localhost centoswxx]# ls -l total 4 drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Desktop drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Documents drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Downloads drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Music drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Pictures drwxrwxrwx. 2 centoswxx centoswxx 18 Mar 11 23:59 POI drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Public drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Templates -rwxr-x-wx. 1 centoswxx centoswxx 131 Mar 11 05:50 test //文件test的所属用户为centoswxx drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Videos [root@localhost centoswxx]# chown root test [root@localhost centoswxx]# ls -l total 4 drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Desktop drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Documents drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Downloads drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Music drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Pictures drwxrwxrwx. 2 centoswxx centoswxx 18 Mar 11 23:59 POI drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Public drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Templates -rwxr-x-wx. 1 root centoswxx 131 Mar 11 05:50 test //文件test的所属用户被修改为root用户 drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Videos [root@localhost centoswxx]# chown :root test [root@localhost centoswxx]# ls -l total 4 drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Desktop drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Documents drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Downloads drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Music drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Pictures drwxrwxrwx. 2 centoswxx centoswxx 18 Mar 11 23:59 POI drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Public drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Templates -rwxr-x-wx. 1 root root 131 Mar 11 05:50 test //文件test的所属用户组被修改为root用户组 drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Videos
添加-R
[root@localhost centoswxx]# ls -l total 4 drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Desktop drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Documents drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Downloads drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Music drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Pictures drwxrwxrwx. 2 centoswxx centoswxx 18 Mar 11 23:59 POI //文件夹POI的所属用户为centoswxx,所属用户组为centoswxx drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Public drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Templates -rwxr-x-wx. 1 root root 131 Mar 11 05:50 test drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Videos [root@localhost centoswxx]# chown -R root:root POI [root@localhost centoswxx]# ls -l total 4 drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Desktop drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Documents drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Downloads drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Music drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Pictures drwxrwxrwx. 2 root root 18 Mar 11 23:59 POI //文件夹POI的所属用户被修改为root,所属用户组被修改为root drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Public drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Templates -rwxr-x-wx. 1 root root 131 Mar 11 05:50 test drwxr-xr-x. 2 centoswxx centoswxx 6 Feb 23 22:46 Videos [root@localhost centoswxx]# cd POI [root@localhost POI]# ls -l total 0 -rwxrwxrwx. 1 root root 0 Mar 11 23:59 Name //文件夹POI中的文件Name的所属用户也被修改为root,所属用户组也被修改为root