File permissions are generally considered to be 0 123 456 789, a total of 10:
0: Represents the file type of the file. In Windows, a file association technology is used to associate the corresponding applications by extension, so that double-clicking on a file can achieve the purpose of calling the corresponding application to open it, which is simple and fast. However, for users, the advantage is convenience, and the disadvantage is that there is a substantial hidden thing: the true type of the file is virtually unrelated to its extension.
For example: a pure text file, I can name it “my song in. mp3”, then double-click under win, will call the corresponding music player to open, the result is obvious, must be wrong. On the other hand, I can name a real MP3 file “Flower Roster. txt”, double-click under win, and usually call the corresponding text editor to open it, but I said you know, the display must be scrambled.
The above two examples are intended to illustrate the point that the true type of a file has nothing to do with its extension.
So how do you know the file type without knowing the file extension? This is true in Linux.
There are only the following file types in Linux:
1. -, ordinary files.
2.d, directory file, D is the abbreviation of directory.
3.l. Soft link file, also known as symbolic link file, s is the abbreviation of soft or symbolic.
4.b, block file, is one kind of device file (and another kind), B is abbreviation of block.
5.c, character file, is also a kind of device file (this is the second kind), C is a character file.
There are only five primitive Linux systems, so the number 0 is only one of the five.
Then you will have doubts.
1. What kind of MP3 file is it? Answer: Ordinary documents.
2. What kind of binary file is it? Answer: Ordinary documents.
3. What kind of text file is it? Answer: Ordinary documents.
4. Why is there no type representation for hard connections? Answer: Hard connection and soft connection, although the name is only one word short, the essence is completely different, hard connection is also a document. Its type is ordinary file.
Why does it say so much? The purpose is to pave the way for the following knowledge.
So 123-456-789 is good to say. People who know this area know that they are just the difference between user-group-other three groups. We can use any one of them as an example to explain rwx.
How should we remember the difference between the two? Do you memorize by rote? NO.
We should know why and why. Next, I try to explain why RWX permissions have different meanings on both sides from the essence of the query file and content.
Understanding what is said below requires knowledge of Linux’s filesystems. If you don’t know the concept of inode, you’re going to suffer a lot.
Again, it is emphasized that the content of the document has nothing to do with the name of the document used at that time, and that the type of the document has nothing to do with the name of the document at that time.
Looking at the contents of a file is actually a process like this:
For example, you use this command: cat/tmp/abc.txt
1. You only pass an absolute path, / TMP / abc. txt. The system first needs to know how much inode is in the / TMP / abc. TXT file. How do you know?
2. Remember a rule that the parent directory of a file knows its inode number! (Now I wonder if you’ve learned something, don’t worry, and look down.)
3. So I get the file name’/ TMP / abc. txt’. I need to know about the / tmp directory first. To know about the / tmp directory, I need to know about the / directory first, so I can start with the / directory (assuming that the inode number of the directory is 0, and this is written to death), and then I can go to a table called inode-table to check it. Look for the data domain to which inode number 0 refers, and then from the data domain you can find something similar to the following: (looks like a table, doesn’t it? As you can imagine, a catalog file is a table that stores what file names are in it and the inode number corresponding to that file name.
File name inode number
Well, we found the inode number corresponding to the name of the’/ tmp’file in the directory file’/’, which is 20. (suppose)
4. Then we use the inode number 20 to find the corresponding data field of 20 in the inode-table, and then from the data field, we will find a table: (Why is it a table again? Because “/” is a directory, and “/ tmp” is a directory, of course, the data domain still contains tables.
File name inode number
Well, we found the inode number of / TMP / abc. txt, which is 8899. According to the above rules, do we have to go to inode-table to find the corresponding data domain 8899? Yes, that’s it.
5. We find the data domain corresponding to inode 8899, so we will find the following contents:
“Abcdefg” (assuming the contents of the file are like this)
There are doubts again. Why is Mao not a watch this time?
Answer: / TMP / abc. TXT file is not a directory file, it is a common file, and it usually stores some strings.
Ordinary file: Store ordinary data, usually string.
Catalog file: A table is stored, which is the mapping relationship between all file names and inodes under the catalog file.
Get the inode number of the file from the parent directory – > Find the starting point and other information in the data field corresponding to the inode number in the inode-table table table – > Go to the data field to read the contents of the file (the contents of ordinary files are usually strings, the contents of directory files are a table).
If you really understand what I said above, then it will be much simpler.
The key is to access any file, depending on whether you can get the inode number, you can’t get it. Just go to the inode table with the inode number. Find the data field, and then you can find the contents of the file.
Then the whole process is not only related to the file permissions, but also to the parent directory (and the parent directory of the parent directory…) permissions (whether we can get the inode of this file)
It is embodied in the command: (in words, this is the most practical representation)
For ordinary files, RWX means:
R: The name and content of this common file can be obtained.
W: You can modify the content and name of this file. You can delete the file, but the user will get prompt to delete the write protection file.
X: Does the file have permission to be executed?
For directory files, RWX means:
R-x: You can enter the directory of CD to get the storage situation in the directory, but you can not modify the name of the files (directories) stored in the directory, nor can you create new files and directories in the directory.
– wx: you can enter the CD directory, but you can not see the storage in the directory (ls is not available), you can add, modify, delete files into the directory. Cat can be used to read the contents of the file or directory in the directory. Because the files can not be stored in the directory, the content of the file can only be obtained by guessing, cat + filename without knowing, so it is still not confidential.
– x: You can enter the directory of CD without seeing the storage, and you can’t add, modify or delete files into the directory. But you can still get the contents of the files in that directory by cat + XX (guess).
RW -: can not enter the CD directory, using LS can only get the file name and directory name, because the inode number of these files can not be obtained, of course, the contents of the files in the directory can not be obtained. You cannot add, modify or delete files to this directory.
1. Although directory files are files (alas, the core idea of who calls them Linux is Everything is file), but the content is stored in a table, about the mapping relationship between file name and inode number.
2. There is no dime relationship between the file extension and the file type.
3. There is not a dime relationship between the file name of the file and the actual content of the file stored.
4. Know how to find the content of a file.
5. Why does the same file system move files faster than across file systems?
Answer: Because you only need to modify the path and inode correspondence in a directory, you don’t need to rewrite the data domain.
6. What is the 500G hard disk that you bought? After formatting, it is always less than 500G?
Answer: As we can see from this article, inode-table also needs to occupy storage space, so inode-table occupies a lot of the missing part.