一、查看文件或文件夹权限

[root@hadoop09-linux etc]# ll -h /etc #ll 是ls -l 的缩写方式 -h文件大小单位k

截取其中三行说明

drwxr-xr-x.  2 root root  4.0K Sep  2 08:19 init
lrwxrwxrwx. 1 root root 11 Sep 2 08:11 init.d -> rc.d/init.d
-rw-r--r--. 1 root root 884 Sep 2 00:26 inittab

分为 6 块(已其中第一行解释)

# drwxr-xr-x.  2 root root  4.0K Sep  2 08:19 init
1. drwxr-xr-x. 注:最后那个点是ls把多acl和selinux属性加进去了,下面只考虑前十位
  第一位表是文件类型 d:目录 -:普通文件 l:链接文件
  此时需要了解权限的分组:
    前三位是文件所有者(user,简写u);中间三位是所在组(group,简写g);后三位其他人(other,简写o);第二位到第10位,即rwxr-xr-x权限
    r:可读,以二进制表示2^2;w:可写,以二进制表示2^1;x:可执行,以二进制表示2^0;-:无所在权限,以二进制表示0)
  例:r-x 权限(可读可执行但不可写,数字表示为4+0+1=5)
    那么rwxr-xr-x中,文件所有者的权限是可读可写可执行(4+2+1=7);
    所在组的权限是可读不可写可执行(4+0+1=5);其他人的权限是可读不可写可执行(4+0+1=5)
    则rwxr-xr-x以数字表示为755
2. 2 代表文件连接数
3. root root 分别代表用户名和用户组
4. 4.0k 代表文件大小
5. Sep 2 08:19 日期
6. init 文件名

一、权限操作

  1. chmod 分配权限

   属性:u(user) g(group) o(other)  a(all)

   a. 权限设置符号:+(添加权限)  -(去掉权限)  =(设置完整权限)

[root@hadoop09-linux tmp]# touch test.txt
[root@hadoop09-linux tmp]# ll
total 0
-rw-r--r--. 1 root root 0 Sep 6 19:58 test.txt
[root@hadoop09-linux tmp]# chmod u+w,g-r,o=rwx test.txt #注意各组权限以,分隔
[root@hadoop09-linux tmp]# ll
total 0
-rw----rwx. 1 root root 0 Sep 6 19:58 test.txt

   b. 以数字形式设置权限

[root@hadoop09-linux tmp]# chmod 777 test.txt #上面已解释7=r+w+x
[root@hadoop09-linux tmp]# ll
total 0
-rwxrwxrwx. 1 root root 0 Sep 6 19:58 test.txt

   c. 递归修改权限,即设置文件夹权限时加上-R,里面的子目录和文件都一并设置

[root@hadoop09-linux test]# ll
total 4
drwxr-xr-x. 3 root root 4096 Sep 6 20:06 test1
-rw-r--r--. 1 root root 0 Sep 6 20:07 test1.txt
-rw-r--r--. 1 root root 0 Sep 6 20:07 test.txt
[root@hadoop09-linux test]# chmod 777 -R ../test
[root@hadoop09-linux test]# ll
total 4
drwxrwxrwx. 3 root root 4096 Sep 6 20:06 test1
-rwxrwxrwx. 1 root root 0 Sep 6 20:07 test1.txt
-rwxrwxrwx. 1 root root 0 Sep 6 20:07 test.txt

  2. chown 修改拥有者

   a. 修改单个文件或文件夹的拥有者

[root@hadoop09-linux test]# ll
total 4
drwxrwxrwx. 3 root root 4096 Sep 6 20:06 test1
-rwxrwxrwx. 1 root root 0 Sep 6 20:07 test1.txt
-rwx------. 1 root root 0 Sep 6 20:07 test.txt
[root@hadoop09-linux test]# chown eRrsr test.txt
[root@hadoop09-linux test]# ll
total 4
drwxrwxrwx. 3 root root 4096 Sep 6 20:06 test1
-rwxrwxrwx. 1 root root 0 Sep 6 20:07 test1.txt
-rwx------. 1 eRrsr root 0 Sep 6 20:07 test.txt

   b. 递归修改文件夹下的所有子目录和文件的拥有者

[root@hadoop09-linux test]# ll
total 4
drwxrwxrwx. 3 root root 4096 Sep 6 20:06 test1
-rwxrwxrwx. 1 root root 0 Sep 6 20:07 test1.txt
-rwx------. 1 eRrsr root 0 Sep 6 20:07 test.txt
[root@hadoop09-linux test]# chown -R eRrsr ../test
[root@hadoop09-linux test]# ll
total 4
drwxrwxrwx. 3 eRrsr root 4096 Sep 6 20:06 test1
-rwxrwxrwx. 1 eRrsr root 0 Sep 6 20:07 test1.txt
-rwx------. 1 eRrsr root 0 Sep 6 20:07 test.txt

  3. chgrp 修改所在组

   a. 修改单个文件或文件夹的所在组

[root@hadoop09-linux test]# ll
total 4
drwxrwxrwx. 3 eRrsr root 4096 Sep 6 20:06 test1
-rwxrwxrwx. 1 eRrsr root 0 Sep 6 20:07 test1.txt
-rwx------. 1 eRrsr root 0 Sep 6 20:07 test.txt
[root@hadoop09-linux test]# chgrp eRrsr test.txt
[root@hadoop09-linux test]# ll
total 4
drwxrwxrwx. 3 eRrsr root 4096 Sep 6 20:06 test1
-rwxrwxrwx. 1 eRrsr root 0 Sep 6 20:07 test1.txt
-rwx------. 1 eRrsr eRrsr 0 Sep 6 20:07 test.txt

   b.  递归修改文件夹下的所有子目录和文件的

[root@hadoop09-linux test]# ll
total 4
drwxrwxrwx. 3 eRrsr root 4096 Sep 6 20:06 test1
-rwxrwxrwx. 1 eRrsr root 0 Sep 6 20:07 test1.txt
-rwx------. 1 eRrsr eRrsr 0 Sep 6 20:07 test.txt
[root@hadoop09-linux test]# chgrp -R eRrsr ../test
[root@hadoop09-linux test]# ll
total 4
drwxrwxrwx. 3 eRrsr eRrsr 4096 Sep 6 20:06 test1
-rwxrwxrwx. 1 eRrsr eRrsr 0 Sep 6 20:07 test1.txt
-rwx------. 1 eRrsr eRrsr 0 Sep 6 20:07 test.txt

需要注意的是:

  如果在/usr/tmp下创建了一个文件夹该文件夹root分给eRrsr所有权限,针对于eRrsr其中的文件或子目录并没有权限,那登录eRrsr后是否能删文件夹内的文件呢?

  可以

PS:对与用户或用户组的修改请查看上一小节

Linux_权限的更多相关文章

  1. linux_权限小练习

    下面是解释: 当前# root用户, ls列出列表 mkdir 新建目录 赋予目录744权限      对others来说是  r--  只可读 touch 新建在目录下的同名文件 赋予文件600权限 ...

  2. Linux_权限管理理论概述

    一.权限定义 1.文件权限作用的对象 owner :属主 - u group :属组 - g other :其他人 - o 2.文件的三种权限 //针对文件的权限 r 可读 可以使用cat命令查看文件 ...

  3. Linux_用户管理&权限管理

    2017年1月11日, 星期三 Linux_用户管理&权限管理 1.  Linux用户管理&权限管理 终端的概念: tty  查看登录的终端 类型  user group    oth ...

  4. Linux_修改创建文件夹时默认权限(修改为能上传)

    1:查看当前权限 umask 0022 意思就是权限为:777-022 =755 读 2:临时修改 umask 020 020 意思为:777-020=757 读写上传 3:永久修改 回到根目录 cd ...

  5. linux_文件权限

    权限贯穿linux整个系统 创建文件或目录,属主和组都是当前用户 linux权限位? 9位基础权限位, 3位一组,总共12位权限 用户对文件权限,相当于你的笔记本 r      读    4 w    ...

  6. linux_修改文件权限chmod 、改变文件/目录所有者chown

    chmod使用事例 数字方法 chmod -R 751 [FILE] ugoa方法 chmod -R u=wrx,g=rx,o=x [FILE] 说明 chmod [OPTION] [MODE] [F ...

  7. Linux_用户和权限管理

    目录 目录 用户管理基础知识 用户管理指令 useradd userdel passwd usermod chage su id who chmod chown s权限t权限 acl 用户管理基础知识 ...

  8. Linux_用户权限管理

    目录 目录 用户管理 useradd创建用户 userdel删除用户 usermod修改用户账号 passwd修改用户密码 用户权限设置 用户组管理 查看用户的属组 修改用户组gpasswd 为没有家 ...

  9. Linux_目录基本操作_常用命令【详解】

    Linux_常用命令 Linux文件系统的目录树结构:[Linux世界里一切皆文件]:说白了,就是文件和文件夹(目录)之间的操作. 普通用户kkb所有文件及文件夹,其实都位于root用户的 /home ...

随机推荐

  1. [unity3d插件]2dtoolkit系列一 创建精灵

    从今天开始要做一个2d游戏,由于之前都是做cocos2dx的,然后接触了一段时间的unity3d,都是做3D方面的东西,得知要做2d游戏还是有点开心的,或许因为不想丢失之前的2d游戏的一些思想,然后接 ...

  2. Toast通知

    win10 app 开发中Toast通知的模板只有一种,统一为 ToastGeneric 通用型通知,本文我们来讲讲 Toast 的 XML文档相关知识. 在以前8.1时候的Toast通知方式,到了W ...

  3. NSFileManager 的基本使用方法

    本方法已有个人总结, int main(int argc, const char * argv[]) { @autoreleasepool { NSString *path=@"/Users ...

  4. BNUOJ1067生成函数入门

    https://www.bnuoj.com/v3/problem_show.php?pid=1067

  5. 提取Windows用户密钥文件cachedump

    提取Windows用户密钥文件cachedump   Windows系统将用户信息和密钥存储在系统存档文件(System hive)和安全存档(Security hive)中.只要提取这些内容,就可以 ...

  6. 分享Kali Linux 2016.2第41周镜像虚拟机

    分享Kali Linux 2016.2第41周镜像虚拟机该虚拟机使用Kali Linux 2016.2第41周镜像文件安装而成,系统已经更新到10月12日.里面已经进行如下配置:(1)设置官方软件源( ...

  7. Android一体式(沉浸式)状态栏的实现

    注:公司开发任务适配是在4.4版本之上进行,所以此适配仅在4.4之上进行测试. 1.主要使用了第三方的开源项目SystemBarTint,github:https://github.com/jgilf ...

  8. DP ZOJ 2745 01-K Code

    题目传送门 题意:要求任意连续子序列中0和1的数量差不超过k的方案数 分析:想好状态其实不难.dp[i][j][k]表示考虑前i长度,后缀中最大的 sum(0) - sum(1) = j, sum ( ...

  9. iOS instancetype or id ?

    The id type simply says a method will return a reference to an object. It could be any object of any ...

  10. HTML元素的属性

    HTML元素的属性,每个元素都有多个属性值 <p>段落标记</p> <font size=“”>字体大小标记</font>size取值1-7 <h ...