CentOS6.4 file attributes and default permissions

Source: Internet
Author: User
: Linux File attributes: the default linux permission is in. we can see that the figure is divided into seven columns. what each column represents? I will explain in detail below. in, we can see the default permissions of the test1 file and the test2 directory file. what does that mean? well, let's talk about it in detail. 1.

: Linux file attributes

: Linux default permissions

In, we can see that the figure is divided into seven columns, each column represents what I will explain in detail below. in, we can see the default permissions of the test1 file and the test2 directory file, what does that mean? well, I don't want to talk about nonsense. let's talk about it in detail.

1. default file attributes

In, we can see that the default attributes of a file are divided into seven columns, and their meanings are as follows:

Column 1: indicates the file type and permission (permission)

File type:
-: Common File (f)
D: directory file
B: block device files)
C: character device file (character)
L: symbolic link file)
P: Command pipeline File (pipe)
S: socket file)

File permission: 9 bits, each 3 bits, each group: rwx (read, write, execute), r --

The first group is the permissions of the file owner. The owner of the file can read and write but cannot execute it;

Group 2: Same group permissions

Group 3: Other permissions not in this group

Column 2: Number of hard links to a file (I will describe it in detail during Disk Management)

Column 3: owner of the file or directory)

Column 4: indicates the group to which the file belongs)

Column 5: size of the file. the default unit is bytes.

Column 6: file creation date or latest modification date

Access: access
Modify: modify. the file content has changed.
Change: change, metadata, metadata

Column 7: file name of this file

2. default permissions for files and directories

From the above explanation, we can see that a file has several attributes, including basic permissions such as read/write operations (r, w, x) and whether it is a directory (d) file (-) and other attributes! The method for modifying attributes is also discussed in my previous blog (chgrp, chown, chmod ). Now we know how to create or change the attributes of a directory or file. however, do you know what the default permissions will be when you create a new file or directory? Hey! It's related to umask! So what is umask doing? Basically, umask specifies the default permissions of the current user when creating a file or directory. how do I know or configure umask?

3. umask (mask code) command

For example:

1 ). you can enter umask directly to view the permission configuration score of the numeric state, or add the-S (Symbolic) option to view the value, the permission is displayed as a symbol type! From the first method, we can see four groups of numbers. should they be three groups? In fact, the first group is used with special permissions. we don't need to worry about it for the time being. I will explain it in detail in the post-blog and sell it first! On the default permission attributes, directories and files are different. We know that the x permission is very important to the Directory (if you do not understand it, you can see the permissions of directories and files )! However, generally, you should not have the operation permission to create a file, because a file is usually used as a data record! Of course, no operation permission is required. Therefore, the default situation is as follows:

If the user creates a "file", the default "no running (x) permission" means that only the rw projects are available, that is, the maximum value is 666. the default permission is as follows:
-Rw-

If the user creates a "directory", x is related to whether the user can access the directory. by default, all permissions are enabled, that is, 777. the default permissions are as follows:
Drwxrwxrwx

2). Note that the umask value refers to "The default value must be removed !" Because r, w, and x are 4, 2, and 1 respectively, so! That is to say, if you want to remove the write permission, that is, minus 2, and if you want to remove the read permission, that is, minus 4, you need to remove the read and write permissions, that is, minus 6, do you need to take away the operation and write permissions, that is, subtract 3? What is 5, please? Haha! Read and run permissions!

As described in the preceding example, because umask is set to 022, the user has not been assigned any permissions, but the permissions of group and others have been removed 2 (w ), when users:

When creating a file: (-rw-)-(----- w -- w-) ==>-rw-r -- (666-umask)

When creating a directory: (drwxrwxrwx)-(d ---- w -- w-) ==> drwxr-xr-x (777-umask)

The above is the role of umask, do you understand? For r, w, and x, they represent 4, 2, and 1 respectively. The following describes in detail (number permission )!

4. importance of directory and file permissions

1). importance of permissions on files

Files actually contain data, including common text files, database content files, binary executable files (binary program), and so on. Therefore, permission is of the following significance for a file:

  • R (read): read the actual content of the file, such as the text content of the text file.

  • W (write): You can edit, add, or modify the content of the file (but not delete the file)

  • X (execute): The file has the permission to be executed by the system.

The readable (r) indicates reading the file content is easy to understand, so what about executable (x? You must be careful here! Because the ability to execute a file under Windows is determined by the extension, for example :. exe ,. bat and so on, but in Linux, whether our files can be executed is determined by whether we have the x permission! There is no absolute relationship with the extension! What about the last w permission? When you have w permissions on a file, you can write, edit, add, or modify the file content, but you do not have the permission to delete the file! For the file rwx, it is mainly for the file content, and it has nothing to do with the existence of the file name! Because the file records actual data!


2). importance of permissions on directories

Files are used to store actual data. What are the main contents used to store? The main contents of a directory are in the list of recorded file names. the file names are strongly correlated with directories! So what is the meaning of the r, w, and x for the directory?

  • R (read contents in directory ):
    Indicates that you have the permission to read the list of directory structures. Therefore, when you have the permission to read (r) a directory, you can query the file name data in the directory. So you can use the ls command to display the content list of this directory!

  • W (modify contents of directory ):
    This writable permission is amazing for the directory! Because it indicates that you have the permission to change the directory structure list, that is, the following permissions:

    • Create a new file and directory

    • Delete an existing file and directory (regardless of the permission of the file !)

    • Rename an existing file or directory

    • Move the files and directories in the directory


    In short, the w permission of the directory is related to the change in the file name under the Directory!


  • X (access directory ):
    What is the purpose of directory execution permission? The directory is just a record file name. it cannot be used for execution? That's right! The directory cannot be executed. Directory x indicates whether the user can enter the directory to become a working directory! The so-called working directory is your current directory! For example, when you log on to Linux, your home directory is your current working directory. The command to change the directory is cd (change directory). If you can change the directory, you have to check the x permission!

5. digital permission

Numeric type and File permission


There are nine basic permissions for Linux files: owner, group, and others. each of the three identities has its own read, write, and execute permissions. first, review the data mentioned above: the file permission character is-rwxrwxrwx. the nine permissions are set by three or three! Here, we can use numbers to represent each permission. the score of each permission is as follows:

R: 4
W: 2
X: 1
The three permissions (r/w/x) of each identity (owner/group/others) must be Accumulated. for example, when the permission is: [-rwxrwx ---] The score is:
Owner = rwx = 4 + 2 + 1 = 7
Group = rwx = 4 + 2 + 1 = 7
Others = --- = 0 + 0 + 0 = 0
So when we change the permission settings, the permission number for this file is 770! Isn't it easy!

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.