• linux中ugo权限管理(chmod/chown)


    查看ugo权限: ll

     [root@localhost test]# ll

    total 12

    -rwxr-xr-x 2 root root 4 Oct  3 11:44 a

    lrwxrwxrwx 1 root root 1 Oct  3 15:57 a.soft -> a

    drwxr-xr-x 2 root root 6 Oct  3 15:54 b

    -rw-r--r-- 1 root root 3 Oct  3 11:09 cron

    -rwxr-xr-x 2 root root 4 Oct  3 11:44 p

    ugo分析说明:

    ugo:  user-group-other  除了x可执行权限,其他对root用户无约束力。

    针对-rw-r--r--的分析:第1位表示文件类型。2-10表示ugo权限,三位一段,一共三段。

    2-4位表示user文件属主权限。5-7位表示group文件属组权限。8-10位表示other权限。

    rwx权限对应的相关命令:

     对普通文件而言:

              r   --cat/tac/more/less/head/tail/vim

              w  ---vim :wq    >  >>   2>    2>>

              x    ---可执行。

    对目录文件而言:

             r         --ls

             w         --mkdir  touch  >  rm

             x          --- cd


    修改
    ugo权限:chmod

    [root@localhost test]# ll

    total 0

    -rw-r--r-- 1 root root 0 Oct  3 17:46 a

    -rw-r--r-- 1 root root 0 Oct  3 17:46 b

    -rw-r--r-- 1 root root 0 Oct  3 17:46 c

    [root@localhost test]# chmod +w a           --单独给userw权限,chmod u+w a  相同。

    [root@localhost test]# chmod a+w b          --ugo都加w权限。


    用8进制数字表示ugo权限:

    数字权限:三位一段,一共三段.(排列顺序必定是rwx,什么都不是,补位-,依次可用4 2 1 0表示)
    r    --read   4

    w  - write    2

    x   --execute  1

    -    --null  0

    [root@localhost test]# chmod 777 d.sh  ---给文件d.shugo都加rwx权限。

    修改文件属主与属组权限:chown  user:group file_name

     修改文件属主和属组:chown user:group file_name

    修改文件属主: chown user file_name

    修改文件属组:chown :group file_name

    修改文件属主及自动匹配属组: chown user:  file_name

    [root@localhost test]# ll e

    -rw-r--r-- 1 root root 0 Oct  3 17:50 e

    [root@localhost test]# id lbg

    uid=1000(lbg) gid=1000(lbg) groups=1000(lbg)

    [root@localhost test]# chown lbg e             --单独修改文件的属主

    [root@localhost test]# ll e

    -rw-r--r-- 1 lbg  root 0 Oct  3 17:50 e

    [root@localhost test]# chown :lbg f

    [root@localhost test]# ll f

    -rw-r--r-- 1 root lbg 0 Oct  3 17:50 f         ----单独修改文件的属组

    [root@localhost test]# chown lbg: g                    --修改文件属主和属组

    [root@localhost test]# ll g

    -rw-r--r-- 1 lbg lbg 0 Oct  3 18:00 g

    对目录权限修改时加上-R表示递归修改.(目录里面文件一起修改.)

    [root@localhost test]# chown -R lbg: ha

    [root@localhost ha]# ll /test/ha

    -rw-r--r-- 1 lbg lbg 0 Oct  3 18:01 1

    -rw-r--r-- 1 lbg lbg 0 Oct  3 18:01 3

  • 相关阅读:
    sqlserver 日期格式化
    CentOS7系统 ansible自动化部署多台服务器部署
    Linux运维跳槽40道面试精华题
    Linux下SVN创建新的项目
    日志切割
    SVN的安装和启动SVN的安装
    jenkins+Gitlab+maven+tomcat实现自动集成、打包、部署
    nginx启动脚本
    nginx如何调用php
    redis常用命令
  • 原文地址:https://www.cnblogs.com/lbg-database/p/10109976.html
Copyright © 2020-2023  润新知