File access permission-detailed explanation of mode bit problems

Source: Internet
Author: User
Article title: detailed explanation of how to access the file-mode bit. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
I. Preface
==========
  
This article describes how to set the access permissions for common files and directories in Linux. This article is written for beginners with a little Foundation (I am also a beginner), as shown in
If you can understand the output meaning of the following lines of the 'ls-L' command (note the ^ bit below), you do not need to read this article.
Time is the most precious thing for you!
  
-R-sr-xr-x 1 root bin 26975 Jun 24 1999 0:32/usr/bin/passwd ----------- 1.1
^
-RwxrwSr-x 1 zyd 12506 Oct 29 test_euid ----------------------- 1.2
^
Drwxrwxrwt 5 root 1024 Nov 1 01; 34/tmp ---------------------- 1.3
^
-Rwxr-xr-x 2 zyd 32506 Oct 19 hard_link --------------------- 1.4
^
Lrwxr-xr-x 1 zyd 1 Oct 23 :40 sym_link->/tmp/sym_target ----------- 1.5
^
  
  
  
II. Introduction to the output format of the 'ls-L' command
======================================
  
The 'ls-L' command displays the file list in long format. the meanings of each field are as follows:
  
Lrwxr-xr-x 1 zyd users 15 Oct 23 :40 sym_link->/tmp/sym_target
____________________________________________________
|
| + -- Symbolic connection (s_link)
|
| + ----- File name (name)
|
| + ---- Last File change time (time)
|
| + ------------ File length in bytes (size)
|
| + ---------- File group)
|
| + -------------------- File owner (user)
|
| + ------- Number of connected digits (count)
|
| + ------- File mode, 9 digits
|
+ ------------ File type (type), occupies one position
  
In addition to s_link, all the preceding nine fields must have different files and directories. The meanings of user, group, time, and name are as follows:
This article will not introduce other fields. other fields will be introduced in this topic section.
  
  
III. file type)
  
Linux supports the following types of files:
1. common file ========>-
2. directory file ========> d
3. symbolic connections ========> l
4. character device file ===> c
5. block device files ======> B
6. named pipe FIFO
7. socket
  
FIFO and socket are beyond the scope of this article. Other files are described as follows:
  
1. Common Files: common files (nonsense !), Myfile created using 'Vi myfile' is a common file, such as executable binary code.
File, script file, ASCII text file, data file, configuration file... can this be explained?
  
2. Directory files: a directory can be understood as a container for storing other files and/or other directories. it is a special file whose content is composed of directory items.
The Directory items mainly include two parts: the file name and the index node number inode. The two are called Connections. we will refer to inode in the following section.
For more details.
  
3. device files: Do you have any DOS experience? if our machine has only three DOS system files, IO. SYS, MSDOS. SYS,
COMMAND. COM, but you need to edit an English document and output it through the printer later. what can you do?
  
Copy con mydoc. TXT
  
Enter the document content here
  
^ + D; end storage
  
Copy mydoc. TXT> PRN; print the document
  
If you are familiar with this process, you will understand the device file. The preceding CON and PRN are two device files defined by DOS, which correspond
Terminal and parallel print port. This design eliminates the need to understand the specific hardware details used by the device and use the external
Device.
  
  
In Linux, device files are classified into three categories: Character devices, block devices, and network devices. to distinguish between them accurately, you may need to write a separate article
Long article, the general situation is: Character devices directly read, do not use a buffer, such as a serial port, terminal, and so on; and block devices are all through the buffer zone
And can only read a certain number of blocks at a time. for example, if a disk needs to read at least one sector (such as 512 bytes) at a time, the block device can
Random read/write; the network device is the socket mentioned above, because I am not familiar with it, I will not talk about it. Device files are generally stored in/dev
You can run the ls-l command to check what is available in the directory? The focus of this article is to introduce common files and directories.
This is the only introduction here.
  
  
IV. index nodes, hard connections, and connection count
====================================
  
1. index node inode:
  
In Linux, an inode number is assigned to each file, which is called an index node. inode can be simply understood as a pointer, which always points to
Specific storage location. The system locates each file by indexing nodes rather than file names. For example:
  
Suppose we have created a text file named mytext in the current directory of the hard disk, with only one line of content:
This is my file.
Of course, this line of text must be stored in a specific location in the disk data area (physically, it must be described by the head number, cylinder number, and sector number. In this example
Suppose they are 1, 20, 30 ).
Assuming the inode is 262457, the system will be able to convert the inode into a specific physical address (1 Magnetic
Header, 20 cylinder, 30 slice), and finally read the file content: "This is my file ."
Therefore, inode is the pointer number pointing to a file data zone. an inode corresponds to the only physical data zone in the system, and is located in two
Files in the same physical data zone must correspond to two different inode numbers respectively.
  
File copy command:
# Cp/home/zyd/mytext newfile
Create a new file newfile in the current working directory. the actual operations include the following three steps:
1. add a directory item to the current directory, fill in the file name field in newfile, and assign a new inode, which is assumed to be 262456.
2. copy the content of the original file (in 1 head, 20 cylinder, 30 slice) to the new idle physical block (assuming 1 head, 20 cylinders, 31 fans ).
Area ).
3. fill in other key information so that the system can convert the physical address through the information and inode number.
  
Therefore, a new inode and a new data zone should be allocated for file replication, although the content of the two files is the same.
  
  
2. hard connection:
When we use a file, it is generally referenced by the file name. Through the above discussion, we know that one inode number must be exactly the same
The data zone of a file corresponds to one by one. Can two or more different file names in a file system correspond to the same file? Answer
Yes. We know that the inode number is recorded in the directory item corresponding to the file name. we can make the directory items of two or more files have
Inode values correspond to the same file. There are several Directory items with the same inode number. let's say that this file has a few
Hardware connections. for common files, the number of connections in the count field of the ls-l command is the number of hard connections in this file. Hard connection
You can use the ln command to establish the connection. for example:
  
# Ln/home/zyd/mytext hardlink_mytext
A new file hardlink_mytext is created, and the inode of this file is also 262457. Creating a hard connection actually only adds
Directory, but copy the file data zone. the original file data zone is shared by two files. This can save a lot of disk space while saving
The two files can be synchronously updated.
  
'Ls-il 'can display the inode of the file (at the leftmost of the following ):
  
262456-rw-r -- 1 zyd 17 Nov 3 14:52 newfile
262457-rw-r -- 2 zyd 17 Nov 3 14:50 hardlink_mytext
262457-rw-r -- 2 zyd 17 Nov 3 14:50 mytext
  
  
3. connection count:
  
As described above, the file connection count field indicates that there are several file directories in the system with the same inode as this file, that is, this file
There are several hard connections. In the preceding example, the count values of the hardlink_mytext and mytext files are both 2.
  
So what is the meaning of the count field of a directory? The count of the directory also indicates how many Directory items direct to this directory, but the details must be
The description must further explain the structure of the VFS file system. for the sake of simplicity, you only need to understand this: (count-2) equals
Number of sub-directories (that is, only the son is included, not the grandson !). For example, if the count field of a directory/abc is 5
The/abc directory must contain three subdirectories.
  
So far, we have introduced important concepts such as common files, directory files, device files, hard connections, connection counts, and index nodes.
  
4. further explanation:
  
Hard-connection files are not actually a new file class.
Related Article

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.