zoukankan      html  css  js  c++  java
  • linux 更改文件权限命令 chmod

    chmod  -change file mode bits :更改文件权限

    chmod是用来改变文件或者目录权限的命令,但只有文件的属主和超级用户(root)才有这种权限。

    更改文件权限的2种方式:

      一、权限字母+操作符表达式

      二、数字方法(常用)

    hmod数字权限方法(推进)

    命令格式:

      chmod  [数字组合]   文件名

    chmod [数字组合] 目录名 -R参数可递归生效(该目录下所有文件或子目录一起改变)

    一、chmod的数字方法的说明:

    r  4
    w  2  
    x  1
    -  0

    例如:

    rwxr-xr-x 755 目录默认权限  

    rw-r--r-- 644文件默认权限

     

    每个三位的权限代码(属主,用户组,其他用户)组合,有8种可

    八进制                    权限
    0                        ---
    1                        --x
    2                        -w-
    3                        -wx
    4                        r--
    5                        r-x
    6                        rw-
    7                        rwx

    举例:

      rw-rw-r-x  代表数字权限:665

      --xr-x-wx  代表数字权限:163

      -wx--x--x  代表数字权限:311

      rwx--xr-x  代表数字权限:715

      -----x-w-  代表数字权限:012

      如果我们仅仅想改变目录的权限,使用chmod不用加任何参数。如果想把目录下的文件和子目录也同时改变,需要使用

    -R参数

    chmod字符式权限表示法

    命令格式:

    Chmod [用户类型] [+ | - | =] [权限字符] 文件名

    表一 详细说明表

    chmod

    用户类型

    操作字符

    权限字符

    文件和目录

    U(user)

    +(增加)

    r

    G(group

    -

    O(others)

    -(减少)

    w

    A(all)

    =(设置)

    x

    说明:

    +:添加某个权限
    -:取消某个权限
    =:取消其他所有权限赋予给定的权限

    chmod u-x test.sh

    [root@MongoDB ~]# chmod u-x test.sh 
    [root@MongoDB ~]# ll
    total 4
    -rw-------. 1 root root 1851 Mar 27 08:38 anaconda-ks.cfg
    -rw-r-xr-x  1 root root    0 Jun  5 06:43 test.sh

    chmod g+w test.sh

    [root@MongoDB ~]# chmod g+w test.sh 
    [root@MongoDB ~]# ll 
    total 4
    -rw-------. 1 root root 1851 Mar 27 08:38 anaconda-ks.cfg
    -rw-rwxr-x  1 root root    0 Jun  5 06:43 test.sh

    chmod g=w,o-x test.sh

    [root@MongoDB ~]# chmod g=w,o-x test.sh 
    [root@MongoDB ~]# ll
    total 4
    -rw-------. 1 root root 1851 Mar 27 08:38 anaconda-ks.cfg
    -rw--w-r--  1 root root    0 Jun  5 06:43 test.sh

    chmod ugo=r test.sh

    [root@MongoDB ~]# chmod ugo=r test.sh 
    [root@MongoDB ~]# ll
    total 4
    -rw-------. 1 root root 1851 Mar 27 08:38 anaconda-ks.cfg
    -r--r--r--  1 root root    0 Jun  5 06:43 test.sh

    chmod a=rw test.sh

    a代表所有 相当于 chmod 777 test.sh

    [root@MongoDB ~]# chmod a=rwx test.sh 
    [root@MongoDB ~]# ll
    total 4
    -rw-------. 1 root root 1851 Mar 27 08:38 anaconda-ks.cfg
    -rwxrwxrwx  1 root root    0 Jun  5 06:43 test.sh
  • 相关阅读:
    Android 开发 深入理解Handler、Looper、Messagequeue 转载
    Android 开发 Handler的基本使用
    Java 学习 注解
    Android 开发 AlarmManager 定时器
    Android 开发 框架系列 百度语音合成
    Android 开发 框架系列 Google的ORM框架 Room
    Android 开发 VectorDrawable 矢量图 (三)矢量图动画
    Android 开发 VectorDrawable 矢量图 (二)了解矢量图属性与绘制
    Android 开发 VectorDrawable 矢量图 (一)了解Android矢量图与获取矢量图
    Android 开发 知晓各种id信息 获取线程ID、activityID、内核ID
  • 原文地址:https://www.cnblogs.com/mingerlcm/p/10977032.html
Copyright © 2011-2022 走看看