In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article to share with you is about linux under ordinary files and directory files what the difference between the content. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.
File permissions can generally be considered as 0 123 456 789, a total of ten digits:
0: Indicates the file type of the file. Windows uses a file association technology, through the extension to associate the corresponding application, so that double-click a file, you can call the corresponding application to open it, so simple and fast. For users, however, the upside is convenience, and the downside is hiding something substantial: the true type of file has virtually nothing to do with its extension.
For example: a pure text file, I can give it the name "my song li. mp3", and then double click on win, will call the corresponding music player to open, the result is obvious, must be wrong. That in turn, a real MP3 file I can also give it the name "roster.txt," double click in win, generally will call the corresponding text editor to open, but I said you also know, the display must be garbled.
The above two examples 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 documents.
2.d, directory file, d is short for directory.
3.l, soft link file, also known as symbolic link file, s is short for soft or symbolic.
4.b, block file, is one type (and another) of device file, b is short for block.
5.c, character file, is also one type of equipment file (this is the second type), c is the character file.
Linux system is the most primitive of these five, so the 0 th, can only be one of the above five.
Then you have questions,
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 hardlinks? Answer: hard connection and soft connection, although the name is only one word, the essence is completely different, hard connection is also a file. The type is normal file.
Why does it say so much? The purpose is to lay the groundwork for the knowledge that follows.
Well, 123-456-789 is easy to say. Anyone who knows this piece knows that they are only the difference between user-group-the other three groups. We can take any of them as an example to explain rwx.
r:read,w:write,x:execute。
How do we remember the difference between the two? Is it rote? NO。
We should know why, below I try to query the file and the nature of the content, to explain why the rwx permission in these two bodies have different meanings!
Understanding what follows requires knowledge of the Linux file system. If you don't know the concept of inode, you will basically suffer.
Again, the content of the document has nothing to do with the file name used at the time of the document, nor does the type of document have anything to do with the file name used at the time of the document.
Looking at the contents of a file is actually a process like this:
For example, you used the command cat/tmp/abc.txt
1. You only pass an absolute path,/tmp/abc.txt. The system first needs to know how many inode is in the/tmp/abc.txt file. How to know?
2. Remember the rule that the parent directory of a file knows the inode number of that file! (Now I wonder if you've realized something. Don't worry, keep looking down.)
3. So I get the file name "/tmp/abc.txt," and I need to know the/tmp directory, and to know the/tmp directory, I need to know the/directory, so I can start with the/directory (assuming the inode number in the/directory is 0, and it's dead), and then I go to a table called inode-table and look up the data field that inode number 0 points to, and from the data field I can find something like this: (looks like a table, doesn't it? In fact, it can be imagined that a directory file is a table that stores what file names it has inside and the inode number corresponding to the file name)
file name inode number
bin 18
var 19
tmp 20
... ...
Okay, we found the inode number for the file name "/tmp" in the directory file "/," which is 20. (Hypothetically)
4. Then we will find the data field corresponding to 20 in inode-table by inode number 20, and then from the data field, we will find a table: (Why table again? Because "/" is a directory,"/tmp" is also a directory, then of course the data field is still stored in the table)
file name inode number
abc.txt 8899
bbb.mp3 10088
kkk.jpg 20000
... ...
Okay, we found the inode number for/tmp/abc.txt, which is 8899. According to the above rules, do we have to go to the inode-table to find the data field corresponding to 8899 again? Yeah, that's it.
5. We find the data field corresponding to inode number 8899, and we find the following:
"abcdefg"(assuming this is the file content)
...
Another question. Why isn't it a watch this time?
Answer: The/tmp/abc.txt file is not a directory file, it is an ordinary file, and it generally stores some strings.
In essence:
Ordinary files: store ordinary data, usually strings.
Directory file: stores a table that maps all file names and inode under the directory file.
Get the inode number of this file from the parent directory---> Find the starting point and other information in the data field corresponding to this inode number in the inode-table---> Go to this data field to read the contents of this file (the contents of ordinary files are generally strings, and the contents of directory files are a table)
If you really understand what I said above, then the rest is much easier.
The key is to access any file, depending on whether you can get the inode number, if you can't get it, you can't do anything. Get the inode to say, take the inode number to the inode table to find, finally find the data field, then you can find the content of the file
And then the whole process--it's not just about permissions on this file, it's also about its parent directory (and the parent directory of the parent directory...) Permission related (whether you can get the inode of this file)
It is reflected in the command: (this is the most practical appearance)
======
For ordinary files, rwx means:
r: You can get the name and content of this common file.
W: You can modify the content and file name of this file. The file can be deleted, but the user will be prompted to delete the write-protected file.
x: Whether the file has permission to be executed.
======
For directory files, rwx means:
r-x: you can enter cd directory, you can get the storage situation under this directory, but you cannot modify the name of the file (directory) stored in this directory, and you cannot create a new file or directory under this directory.
-wx: You can enter cd directory, but you can't see the storage situation under this directory (ls is unavailable). You can add, modify and delete files under this directory. You can read the contents of the file or directory under the directory through cat, because you can't get those files stored under the directory, you can only guess the file content through cat + file name without knowing it, so it is still not confidential.
--x: You can enter cd directory, you can't see the storage situation, and you can't add, modify or delete files under this directory. But you can still get the contents of files in that directory by cat + xx (guess).
rw-: Cannot enter cd directory, only file name and directory name can be obtained with ls, because the inode number of these files cannot be obtained, and of course, the contents of files under this directory cannot be obtained. You cannot add, modify or delete files to this directory.
======
To sum up:
1. Although a directory file is a file (alas, the core idea of who called Linux is that Everything is a file), it is only a table that stores the contents, and the mapping relationship between file names and inode numbers.
2. There is no relationship between file extensions and file types.
3. There is no relationship between the file name and the actual content of the file.
4. Learn how to find the contents of a file.
5. Why is it faster to move files within the same file system 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 field again.
6. What is the 500 gigabyte hard disk bought, after formatting is always less than 500 gigabytes?
A: As can be seen from this article, inode-table also needs to occupy storage space, so the missing part of inode-table occupies a lot.
Thank you for reading! About "linux under ordinary files and directory files what are the differences" this article is shared here, I hope the above content can be of some help to everyone, so that we can learn more knowledge, if you think the article is good, you can share it to let more people see it!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.