Linux file attributes and permission learning-Analysis of LS command results

Source: Internet
Author: User

Http://blog.csdn.net/sfrysh/article/details/6538391

 I recently read "laruence's Linux private house dish", which is indeed a good book that gives me a deep understanding of file attributes and permissions. The summary is as follows.

(Note: The pictures in this blog post are from the book "laruence's Linux house dish)

I. Outline

This blog includes the following parts:

1. Concepts of users and user groups;

2. file attributes;

3. Differences between directories and general files;

4. detailed instructions on the use of LS commands;

2. Users and user groups

The Linux system is "multi-user, multi-task environment", that is, "the Linux system allows multiple users to use the system at the same time and execute different tasks at the same time ". Therefore, to ensure file security for each user, the Linux system has a very strict file permission management mechanism.

It is mainly reflected in two aspects:

1. File Operation permissions:

Three types: read, write, and execute.

2. File Access Method:

Three types: Owner/group/Other.

The read, write, and execute permissions are easy to understand, and are mainly used to access files. Their meanings are as follows:

Owner
That is, the owner of the file, usually the user who creates the file. In Linux, each file has an owner. Each user is assigned a unique uid.

User Group
A user group contains several users. It is worth noting that a user can belong to multiple user groups or not to any user group. Each user group is assigned a unique GID.

Others
For a file, if a user is neither the owner nor the owner is in the same user group, the user is the other person in the file.

In Linux,

① Information of each user account is stored in the/etc/passwd file;

② The password is stored in the/etc/shadow file;

③ The user group information is stored in the/etc/group file.

Iii. File Attributes

Execute the "ls-Al" command in the command line. We will see a detailed list in the form of each line of the list:

 

The meanings of each part are as follows:

 

Numbers from left to right. The meaning of each field is as follows:

1. File Attributes. There are 10 attributes in total. For details, see:

The first attribute indicates the type of the file. common attributes include files, directories, and connection files.
"D": indicates a directory );

"-": Indicates a file;

"L": indicates a connection file );

In the last nine attributes, each of the three digits is a group. "R" indicates read, "W" indicates write, and "X" indicates executable ).
The first group is "permissions of the owner ";

The second group is "same User Group Permissions ";

The third group is "others' Permissions ";

Combining these two points: the 10 attributes in the preceding figure mean that a file is readable, writable, and executable, "persons in the same user group" are also readable, writable, and executable, but "Others" do not have any permissions.

2. The second column indicates the node occupied by the link. This is mainly related to the link node. For Linux beginners, you do not need to study it first.

3. The third column indicates the "owner" of the file, that is, the owner.

4. Column 4 indicates the owner's "user group ".

5. The fifth column indicates the file size.

6. The sixth column indicates the last "modification time" (mtime) of the file, and the time when the file is created.

In addition, the "file time" in Linux mainly includes three parts:

Modification time (mtime): This attribute is updated when the current file "content data" is changed. The time displayed by using the LS command is "modification time mtime ".

Status time (ctime): This attribute is updated when the file status changes. For example, when updating the permissions and attributes of a file.

Access time (atime): This attribute is updated when the file content is read.

 

Note: If you only change the file content, the "status time ctime" will change, but the "modification time mtime" will not change because the file content data has not changed.

7. The seventh column is the file name. Note: in Linux, if a file name starts with ".", this file is a hidden file, which is different from windows.

Iv. Differences between directories and General Files

In Linux, directories also belong to files. For directory files, the meaning of R/W/X is slightly different from that of general files.

R (read contents in directory): With this permission, you can read the directory structure, that is, you can use the LS command to list the directory content.
W (modify contents of directory): With this permission, you can change the directory structure. Common Operations are:
--- Create new files and directories;

--- Delete files and directories;

--- Rename files and directories;

--- Move files and directories;

X (Access Directory): determines whether the directory can be accessed. If your account does not have the X permission for a directory, you cannot access the directory when using the CD command.
A good example is provided in the book "laruence's Linux private house dish", as follows:

 

 

5. How to Use the LS command

Ls is the abbreviation of list, used to display files and directories. This command uses a lot of commands, similar to dir in Windows (DIR commands are also provided in many Linux versions). DIR is short for directory.

Common parameters include:

View plaincopy to clipboardprint?
Command Format:
Ls [-aadffhilnrrst] Directory Name
-A: All files are listed together with hidden files (Files starting;
-A: All files, together with hidden files, excluding the two directories, "." and;
-D: only list the directory itself, not the file data in the directory;
-F: directly list the results without sorting them (LS defaults will be sorted by file name !);
-F: attaches a Data Structure Based on files, directories, and other information, for example:
*: Indicates an executable file;/: indicates a directory;
-L: Serial Output of long data, including the attributes and permissions of the file;
-N: lists the names of UID and GID instead of the user and group;
-R: It is listed together with the sub-directory content, which means all files under the directory will be displayed;
-S: sort by file capacity, rather than by file name;
-T: sort by time instead of by file name.
Command Format:
Ls [-aadffhilnrrst] Directory Name
-A: All files are listed together with hidden files (Files starting;
-A: All files, together with hidden files, excluding the two directories, "." and;
-D: only list the directory itself, not the file data in the directory;
-F: directly list the results without sorting them (LS defaults will be sorted by file name !);
-F: attaches a Data Structure Based on files, directories, and other information, for example:
*: Indicates an executable file;/: indicates a directory;
-L: Serial Output of long data, including the attributes and permissions of the file;
-N: lists the names of UID and GID instead of the user and group;
-R: It is listed together with the sub-directory content, which means all files under the directory will be displayed;
-S: sort by file capacity, rather than by file name;
-T: sort by time instead of by file name.

The following is an example of how to use the LS command:

 

 

 

 

In addition, in many Linux versions, "ls-L" is very common, so it can often be abbreviated as "ll" (two subtitles in lowercase ).

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.