34.权限管理命令

权限管理命令:
chmod命令:
三类用户:
u:属主
g:属组
o:其他
a:所有


    1. 赋权、授权表示法*

                                  u、g、o、a分别代表:属主、属组、其他人、所有人
      
                                +:在原来权限的基础上增加权限
      
               -:在原来权限的基础上去除权限
      
                                   =:直接定义权限
      
                                   r、w、x:读、写、执行
      
              注意:用户仅能修改属主为自己的那些文件的权限;
      
                          实例:
      
                          [root@itxuezhe tmp]# ll fstab 
                          -rw-r--r--. 1 root root 541 2月  23 19:00 fstab
      
                          [root@itxuezhe tmp]# chmod g=rw fstab 
      
                          [root@itxuezhe tmp]# ll fstab 
                          -rw-rw-r--. 1 root root 541 2月  23 19:00 fstab
      
                          [root@itxuezhe tmp]# chmod ug=r fstab 
                          [root@itxuezhe tmp]# ll fstab 
                          -r--r--r--. 1 root root 541 2月  23 19:00 fstab
      
                          [root@itxuezhe tmp]# chmod u=rwx,g=rw,o= fstab 
                          [root@itxuezhe tmp]# ll fstab 
                          -rwxrw----. 1 root root 541 2月  23 19:00 fstab
      
                          [root@itxuezhe tmp]# chmod u=rwx,g=rw,o= fstab 
                          [root@itxuezhe tmp]# ll fstab 
                          -rwxrw----. 1 root root 541 2月  23 19:00 fstab
      
                          [root@itxuezhe tmp]# chmod u-x fstab 
                          [root@itxuezhe tmp]# ll fstab 
                          -rw-rw----. 1 root root 541 2月  23 19:00 fstab
      
                          [root@itxuezhe tmp]# chmod o+r fstab 
                          [root@itxuezhe tmp]# ll fstab 
                          -rw-rw-r--. 1 root root 541 2月  23 19:00 fstab
      
                          [root@itxuezhe tmp]# chmod ug+x fstab 
                          [root@itxuezhe tmp]# ll fstab 
                          -rwxrwxr--. 1 root root 541 2月  23 19:00 fstab
      
                          [root@itxuezhe tmp]# chmod g-wx fstab 
                          [root@itxuezhe tmp]# ll fstab 
                          -rwxr--r--. 1 root root 541 2月  23 19:00 fstab
      
                          [root@itxuezhe tmp]# ll fstab 
                          -rw-r--r--. 1 root root 541 2月  23 19:00 fstab
                          [root@itxuezhe tmp]# chmod -r fstab 
                      [root@itxuezhe tmp]# ll fstab
                          --w-------. 1 root root 541 2月  23 19:00 fstab
      
                          [root@itxuezhe tmp]# chmod u+x,g+w fstab 
                          [root@itxuezhe tmp]# ll fstab 
                          --wx-w----. 1 root root 541 2月  23 19:00 fstab

2.八进制表示法:

34.权限管理命令

    实例:

                    [root@itxuezhe tmp]# chmod 666 fstab 
                    [root@itxuezhe tmp]# ll fstab 
                    -rw-rw-rw-. 1 root root 541 2月  23 19:00 fstab

                [root@itxuezhe tmp]# chmod 644 fstab 
                [root@itxuezhe tmp]# ll fstab 
                -rw-r--r--. 1 root root 541 2月  23 19:00 fstab

  1. chmod –reperence=文件1 文件2 // 以文件1的权限为标准修改文件2的权限

        实例:
    
        [root@itxuezhe tmp]# ls -l /var/log/messages 
        -rw-------. 1 root root 1116015 2月  23 19:20 /var/log/messages
    
        [root@itxuezhe tmp]# ll fstab 
        -rwxrw-rw-. 1 root root 541 2月  23 19:00 fstab
    
        **参考/var/log/messages 的权限去修改/tmp/fstab**    
    
      [root@itxuezhe tmp]# ll fstab 
        -rwxrw-rw-. 1 root root 541 2月  23 19:00 fstab
    
        [root@itxuezhe tmp]# chmod --reference=/var/log/messages fstab 
        [root@itxuezhe tmp]# ll fstab 
        -rw-------. 1 root root 541 2月  23 19:00 fstab

                选项:
                    -R:递归修改;

                    [root@itxuezhe tmp]# chmod 700 skel/ -R
                    [root@itxuezhe tmp]# ll skel/ -a 
                    总用量 16
                    drwx------.  3 root root   78 2月  23 19:57 .
                    drwxrwxrwt. 21 root root 4096 2月  23 19:59 ..
                    -rwx------.  1 root root   18 2月  23 19:57 .bash_logout
                    -rwx------.  1 root root  193 2月  23 19:57 .bash_profile
                    -rwx------.  1 root root  231 2月  23 19:57 .bashrc
                    drwx------.  4 root root   39 2月  23 19:57 .mozilla

    从属关系管理命令:chown, chgrp

                chown命令:

                            选项:
                                -R:     

                实例:

                                [root@itxuezhe tmp]# ll fstab 
                                -rw-------. 1 itxuezhe itxuezhe 541 2月  23 19:00 fstab

                                [root@itxuezhe tmp]# chown -R root:root fstab 
                                [root@itxuezhe tmp]# ll fstab 
                                -rw-------. 1 root root 541 2月  23 19:00 fstab

                                [root@itxuezhe tmp]# chown -R itxuezhe.itxuezhe fstab 
                                [root@itxuezhe tmp]# ll fstab 
                                -rw-------. 1 itxuezhe itxuezhe 541 2月  23 19:00 fstab

        **  参考/tmp/tracker-extract-files.1000的属主和属组权限修改/tmp/skel/目录下的文件文件**

        [root@itxuezhe tmp]# ll -d tracker-extract-files.1000/
        drwx------. 2 itxuezhe itxuezhe 6 2月  19 19:01 tracker-extract-files.1000/

        [root@itxuezhe tmp]# chown -R --reference=/tmp/tracker-extract-files.1000/ /tmp/skel/

        [root@itxuezhe tmp]# ll -a skel/
        总用量 16
        drwx------.  3 itxuezhe itxuezhe   78 2月  23 19:57 .
        drwxrwxrwt. 21 root     root     4096 2月  23 20:13 ..
        -rwx------.  1 itxuezhe itxuezhe   18 2月  23 19:57 .bash_logout
        -rwx------.  1 itxuezhe itxuezhe  193 2月  23 19:57 .bash_profile
        -rwx------.  1 itxuezhe itxuezhe  231 2月  23 19:57 .bashrc
        drwx------.  4 itxuezhe itxuezhe   39 2月  23 19:57 .mozilla

                chgrp命令:

                    注意:仅管理员可修改文件的属主和属组;

    umask:文件的权限反向掩码,遮罩码;
                文件:666 - umask
                目录:777 - umask

                注意:之所以文件用666去减,表示文件默认不能拥有执行权限:如果减得的结果中有执行权限,则需要将其加1;
                            umask:023
                                    666 - 023 = 644
                                    777 - 023 = 754

                    umask命令:
                                umask:查看当前umask
                                umask ###:设置umask

                        注意:此类设定仅对当前shell进程有效;

34.权限管理命令

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章