zoukankan      html  css  js  c++  java
  • 每天一个Linux命令(8):chmod命令

    chmod命令用来变更文件或目录的权限。

    权限范围的表示法如下:

    u   User,即文件或目录的拥有者;
    g  Group,即文件或目录的所属群组;
    o   Other,除了文件或目录拥有者或所属群组之外,其他用户皆属于这个范围;
    a   All,即全部的用户,包含拥有者,所属群组以及其他用户;
    r   读取权限,数字代号为“4”;
    w   写入权限,数字代号为“2”;
    x   执行或切换权限,数字代号为“1”;
    -   不具任何权限,数字代号为“0”;
    s   特殊功能说明:变更文件或目录的权限。

    语法

    chmod(选项)(参数)

    选项

    -c或——changes:效果类似“-v”参数,但仅回报更改的部分;
    -f或--quiet或——silent:不显示错误信息;
    -R或——recursive:递归处理,将指令目录下的所有文件及子目录一并处理;
    -v或——verbose:显示指令执行过程;
    --reference=<参考文件或目录>:把指定文件或目录的所属群组全部设成和参考文件或目录的所属群组相同;
    <权限范围>+<权限设置>:开启权限范围的文件或目录的该选项权限设置;
    <权限范围>-<权限设置>:关闭权限范围的文件或目录的该选项权限设置;
    <权限范围>=<权限设置>:指定权限范围的文件或目录的该选项权限设置;

    参数

    权限模式:指定文件的权限模式;
    文件:要改变权限的文件。

    实例

    [root@centos6 Documents]# ls -l
    total 4
    drwxr-xr-x. 2 root root 4096 Aug 29 15:13 project

    修改目录project权限为drwx------

    [root@centos6 Documents]# chmod 700 project
    [root@centos6 Documents]# ls -l
    total 4
    drwx------. 2 root root 4096 Aug 29 15:13 project
    或者
    [root@centos6 Documents]# chmod u=rwx,go=- project
    [root@centos6 Documents]# ls -l
    total 4
    drwx------. 2 root root 4096 Aug 29 15:13 project

    修改目录project权限为dr-xr-xr--

    [root@centos6 Documents]# chmod 554 project
    [root@centos6 Documents]# ls -l
    total 4
    dr-xr-xr--. 2 root root 4096 Aug 29 15:13 project
    或者
    [root@centos6 Documents]# chmod u=rx,g=rx,o=r project
    [root@centos6 Documents]# ls -l
    total 4
    dr-xr-xr--. 2 root root 4096 Aug 29 15:13 project

    给目录project自己取消写入(w)权限,组员添加可读(r)和可执行(x)权限,其他添加可读(r)权限

    [root@centos6 Documents]# ls -l
    total 4
    drwx------. 2 root root 4096 Aug 29 15:13 project
    [root@centos6 Documents]# chmod u-w,g+rx,o+r project
    [root@centos6 Documents]# ls -l
    total 4
    dr-xr-xr--. 2 root root 4096 Aug 29 15:13 project
  • 相关阅读:
    SDUT 2143 图结构练习——最短路径 SPFA模板,方便以后用。。 Anti
    SDUT ACM 1002 Biorhythms 中国剩余定理 Anti
    nyist OJ 119 士兵杀敌(三) RMQ问题 Anti
    SDUT ACM 2157 Greatest Number Anti
    SDUT ACM 2622 最短路径 二维SPFA启蒙题。。 Anti
    二叉索引树 区间信息的维护与查询 Anti
    SDUT ACM 2600 子节点计数 Anti
    UVA 1428 Ping pong 二叉索引树标准用法 Anti
    2010圣诞Google首页效果
    Object
  • 原文地址:https://www.cnblogs.com/Jimc/p/9554641.html
Copyright © 2011-2022 走看看