Linux's chmod and symbolic link__linux

Source: Internet
Author: User
Tags chmod
1 Overview

The most commonly used forms are:

chmod [-FVR] mode file

Then we look at some of its parameters through the man:

     The generic options are as follows:-F do not display a diagnostic message if chmod could not modify the

     mode for file.  -H If the-r option is specified, symbolic links on the command line are followed.

     (Symbolic links encountered in the traversal are not followed by default.)  -H If The file is a symbolic link, change the mode of the the link itself rather than the "file" link

     Points to.

     -L If the-r option is specified, all symbolic links are followed.
             -P If the-r option is specified, no symbolic links are followed.

     This is the default.

     -R Change the modes of the file hierarchies rooted in the files instead of just the files themselves.  -V cause chmod to be verbose, showing filenames as the ' mode is modi-fied. IF THE-V flag is specified to than once, the old and chmod [-FHV] [-R [-H |-l |-p]] [-e] File ... chmod [-FHV] [-R [-H |-l |-p]] [-c] File ... chmod [-FHV] [-R [-H |-l |-p]] [-n] File ... 

In fact, the most commonly used parameter is-r: process all files in the specified directory and its subdirectories. Then there is the problem, which is to deal with the more specific symbolic link. If you do not need to process symbolic link then the following parameters indicate that you can skip. Special case of symbolic link exists in the command line :-H and-r: If symbolic link is in the file specified by the command line, the command will find the directory or file recursively via symbolic link;- P and-R are used together: and-H means exactly the opposite, and if you do not display the setting,-P is the default setting;-L and-R are used together: all symbolic link will be followed-H: Changing only the properties of symbolic link. 2 Character Setting method

permission Range (WHO):
U:user, the current user of the directory or file
G:group, the current group of directories or files
O:other, in addition to the directory or file of users or groups outside the current user or group
A:all, all users and groups

Action:
+: Increase Permissions
-: Delete Permissions
=: Specify permissions directly

permission characters (mode)
R: Read permission, = = 4
W: Write permission, = = 2
X: Execute permission, = = 1

chmod [who] [+ | - | =] [mode] File name
3 Number Setting method

Numbers correspond to characters as follows:
R=4,w=2,x=1

To rwx the property 4+2+1=7
To rw-the property 4+2=6
To r-x the property 4+1=7

chmod [mode] filename
4 Symbolic Link's permissions issue

New sample file:

Because test1.py does not have execute permissions on the current user, the error occurs if the file is executed:

We add execution privileges to the current user:

As you can see, the executable file turns red, and then execution succeeds. Also, we simply changed the permissions of the test1.py, and the permissions of the Test1.slink files automatically became consistent. So, if you change the Test1.slink permissions, test1.py's permissions will change accordingly. The result is that link's permissions have not changed, and the original file's permissions have changed ...

Of course, this is not to say that the slink file can be executed, it is still in the original file:

Therefore, if the file on the command line is slink, the modification of the permission will directly affect the original file and will not change the Slink permission attribute. But there's also a reference to the argument-h in the overview, and let's see what happens if we use it.

summarizing Symbolic Link's permissions is not important, it is just an indicative file of the original document. So if you call the-h parameter, just modify symbolic Link's permissions, in fact, there is no effect on the original. As the example shows, Slink is unreadable, but the original file is readable, but we can still read the original file through Slink. By default, the right to modify symbolic link is reflected to the original file, and symbolic link itself does not update the permissions. To modify the permissions of the original file, Symbolic Link's permissions are updated.

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.