Linux change file or directory permissions

Source: Internet
Author: User

chmod (change mode) changing permissions
    • What do you think about permissions?

[[email protected] ~]# ls-l total usage 8-rw-r--r--. 1 root root 0 June 8 14:16 2.txt-rw-------. 1 root root 7728 June 6 22:11 anaconda-ks.cfg.1

-rw-r--r--.   this paragraph, except the first . Indicates whether the file is subject to selinux limit * (SELinux if disabled, the new file/directory will not have this point, otherwise there will be) *, the middle of the nine-bit, Represents the permissions for the file or folder.

    • Break down nine-bit permissions, one for every three bits

The first three bits represent the permissions of the file/directory owner.

The middle three bits represent the permissions of all the members in the group to which the file/directory belongs

The last three bits represent the way out of the owner and the owning group, other users ' permissions to the file/directory.

    • Explain RWX (-the location of the symbol, indicating that there is no corresponding permission)

R:read--Read w:write--write X:execute--and execute

-rw-r--r--. 1 root root 0 June 8 14:16 2.txt

Root user has r and W permissions for 2.txt files, no X permissions root user group has R permissions on 2.txt files, no W and x permissions other users have R permissions on 2.txt files, no W and x permissions

    • Rwx can also be represented by numbers.

x--2 of 0 Square W--and 2 of 1 square R--and 2 of 2 times the number of each segment is added to get the corresponding user's permission number for the file   rw-r--r--   equals 6 4 4

    • Change File/directory permissions

    1. Permissions that are represented using numbers

[[email protected] ~]# chmod 2.txt[[email protected] ~]# ls-l total usage 8-rwx------. 1 root root 0 June 8 14:16 2.txt-rw-------. 1 root root 7728 June 6 22:11 anaconda-ks.cfg.1
2. Permissions represented with R,w,x
[[email protected] ~]# chmod u=rw,g=rx,o=x 2.txt[[email protected] ~]#  ls -l Total dosage  8-rw-r-x--x. 1 root root    0 6 month     8 14:16 2.TXT-RW-------.  1 root root 7728 6 Month    6  22:11 anaconda-ks.cfg.1 
> U--user> G--and group> O--and other**== special note: Use this way, can not be written u=rw-,g=r-x,o=--x, the middle can not appear-, although sometimes can be passed, but this write is not Reasonable. As you will see later, there is a way to modify permissions by using the "+" or "-" numbers to control the increase and decrease of permissions. ==**3. Control permissions with +-sign
[Email protected] ~]# chmod a+x 2.txt[[email protected] ~]# ls-l total usage 8-rwxr-x--x. 1 root root 0 June 8 14:16 2.txt
> A--all, A + x, and all users add x permissions to the file/directory.
[Email protected] ~]# chmod a-r 2.txt[[email protected] ~]# ls-l total usage 8--wx--x--x. 1 root root 0 June 8 14:16 2.txt
> Reduce R permissions for files/directories for all users
[Email protected] ~]# chmod u+r 2.txt[[email protected] ~]# ls-l total usage 8-rwx--x--x. 1 root root 0 June 8 14:16 2.txt
> Add R permissions to user alone.
    • -ROptions

Modify permissions, all files within the directory, subdirectories are in effect

[[email protected] ~]# tree /tmp/allinlinux//tmp/allinlinux/└── 1.txt0  directories, 1 file[[email protected] ~]# ls -l /tmp/allinlinux/Total Dosage  0- Rw-r--r--.  1 root root 0 6 Month    8 14:58 1.txt[[email  Protected] ~]# ls -l /tmp/allinlinux/1.txt -rw-r--r--.  1 root root  0 6 month    8 14:58 /tmp/allinlinux/1.txt 

/tmp/allinlinux directory has a 1.txt file allinlinux/the permission to the directory is   1.txt file permissions are

[[email protected] ~]# chmod -r 777 /tmp/allinlinux/[[email protected]  ~]# ls -l /tmp/allinlinux/Total dosage  0-rwxrwxrwx. 1 root root 0 6 Month    8 14:58 1.txt[[email protected] ~]# ls -l /tmp/allinlinux /1.txt -rwxrwxrwx. 1 root root 0 6 Month    8 14:58 /tmp/ Allinlinux/1.txt 

The permissions for the/allinlinux/directory and its files have changed.


This article is from the "Linux Road" blog, make sure to keep this source http://allin28.blog.51cto.com/12931477/1933854

Linux change file or directory permissions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.