Home > Operation and Maintenance > Linux Operation and Maintenance > What does a linux file look like?

What does a linux file look like?

青灯夜游
Release: 2023-03-17 09:30:56
Original
1273 people have browsed it

Linux files are directories (files). In order to facilitate the management of files and directories, the Linux system organizes them into an inverted tree structure starting from the root directory "/". Directories in Linux are similar to folders in Windows systems. The difference is that directories in Linux systems are also treated as files.

What does a linux file look like?

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

Linux files are directories (files).

In order to facilitate the management of files and directories, the Linux system organizes them into an inverted tree structure starting from the root directory /. Directories in Linux are similar to folders in Windows systems. The difference is that directories in Linux systems are also treated as files.

In the Linux operating system, all files and directories are organized into an inverted tree structure starting from a root node "/", as shown in Figure 1.

What does a linux file look like?
Figure 1 Linux system file and directory organization diagram

Among them, the directory is equivalent to the folder in Windows. The directory can store either files or are other subdirectories, and the real information is stored in the file.

The top level of the file system starts from the root directory. The system uses "/" to represent the root directory. Below the root directory can be either a directory or a file, and each directory has Can contain (sub)directories or files. Repeatedly, a huge file system can be formed.

In fact, the main purpose of using this tree-like and hierarchical file structure is to facilitate the management and maintenance of the file system. Imagine if all the files were placed in one directory, the management and maintenance of the file system would be Maintenance will become a nightmare.

There are many similar examples in reality. For example, in the entire administrative system, villagers are equivalent to files. They live in a village, and the village is the directory where villagers are stored. Many villages form a township, which is equivalent to a directory of stored villages, and so on, ultimately building a huge administrative regional management structure chart.

Note that directory names or file names are case-sensitive. For example, dog, DOG and Dog are 3 different directories or files. A complete directory or file path consists of a series of directory names, each of which is separated by "/". For example, the full path of cat is /home/cat.

In the file system, there are two special directories. One is the working directory of the user, which is the current directory, which can be represented by a dot "."; the other is the directory above the current directory, also It is called the parent directory and is represented by two dots "..".

If a directory or file name starts with a dot, it means that the directory or file is a hidden directory or file. That is, when searching in the default way (search commands will be discussed later), the directory or file will not be displayed.

In order to facilitate management and maintenance, the Linux system adopts the file system hierarchy standard, also known as the FHS standard, which stipulates what types of files (or subdirectories) should exist in each directory under the root directory, for example, Executable files should be stored in the /bin and /sbin directories

linux file system (filesystem)

The physical composition of the hard disk

First of all, let’s briefly understand the physical structure of the hard disk. Generally speaking, the hard disk structure includes: platter, magnetic head, platter spindle, control Motor, head controller, data converter, interface, cache and other parts. All platters (usually there are multiple platters in a hard disk, and the platters are parallel) are fixed on a spindle. There is a magnetic head on the storage surface of each disk. The distance between the magnetic head and the disk is very small (so it is easy to be damaged by severe vibration). The magnetic head is connected to a magnetic head controller to uniformly control the movement of each magnetic head. The magnetic head moves along the radius of the disk, and the disk rotates at high speed in the specified direction, so that the magnetic head can reach any position on the disk.

A disk is composed of multiple rings. These rings are called tracks, and a track is divided into multiple sectors (sectors). Each sector is 512Byte, and the rings are at the same position on all disks of the hard disk. Form a magnetic cylinder (Cylinder). The hard disk capacity is: 512Byte * Number of sectors * Number of magnetic columns * Number of heads

The first three numbers are easy to understand. Some people may not understand what is multiplied by the number of heads, because the first three numbers are equivalent to calculation The storage capacity of a circle, and a magnetic head reads a circle, so multiplying by the number of magnetic heads is equivalent to the circle area multiplied by the number of circles.

Disk partitioning

The smallest unit of disk partitioning is the magnetic cylinder (Cylinder)

Disk partitioning is actually recording the starting and ending magnetic cylinders of a partition (partition), and these recorded information are stored in the main boot sector (Master Boot Recorder, MBR). In fact, the MBR is on the zeroth track of a hard disk. This is also the first area that must be read when the computer is turned on to use the hard disk.

Think about a question: Is the size of the MBR fixed?

We think about it this way, the storage order of data is: MBR other data. If the size of the MBR is not fixed, for example, the information of three partitions was originally stored in the MBR, and now we want to add a new partition, what will be the consequences? The consequence is that all "other data" must be sequentially moved backward by the distance of one partition information. Have you thought about adding or deleting arrays? So we hope to fix the MBR, and this is also true. The MBR is fixed to only store the information of 4 partitions. This seems much better, but there are only four partitions, is it enough? Of course, the designer also thought about this problem, so he divided the partition into two categories: Primary and Extended (there can only be one E at most). Among them, P can be used directly, but E cannot be used directly. E is equivalent to a pointer pointing to the location information storage location of the extended partition.

filesystem

filesystem is also the file system. Each oartition can have its own filesystem, such as fat32, Different partitions such as ntfs have different file systems, but they are all used to store data. Earlier we introduced that the smallest storage unit of the hard disk is sector (sector, generally 512Byte), but the smallest storage unit of filesystem is not sector but block. Block is a power multiple of 2 of sector, and the head reads data of one block at a time. Therefore, if the block is too small, the magnetic head needs to read a larger number of blocks when reading a file, which is very inefficient. However, the block cannot be too large because only one file can exist in a block. For example, the block size is 100M. , then if there is a 100.1M file, it needs to occupy two blocks, which wastes a lot of space.

superblockThe first block in each filesystem is called superblock. The role of the superblock is to store the size of the filesystem, empty and filled blocks, and other general information such as this. In other words, if you want to use a filesystem, the first block you have to go through is the superblock. If the superblock is broken, there will probably be no way to save this partition.

linux’s EXT2 file systemSince we are learning linux, we naturally have to learn linux’s filessystem. The most standard EXT2 for Linux is explained.

The filesystem in EXT2 is divided into inode area and block area. The inode stores the related attributes and other information of the file, while the block area stores the content of the file. Each inode acts as a pointer, which can describe the file. The relevant attributes of the file and point to the location of the block where the file is located. The number of blocks and inodes is fixed at the time of initial formatting.

Schematic diagram of the entire filesystem:

What does a linux file look like?

SuperBlock: As mentioned above, Superblock is the place where relevant information of the entire filesystem is recorded. Without Superblock, there would be no This filesystem. The information he records mainly includes:
  • The total amount of blocks and inodes;
    • The number of unused and used inodes/blocks;
    • The size of one block and one inode ;
    • Filesystem's mounting time, the last time data was written, the last disk check (fsck) time and other file system related information;
    • A valid bit value, if this If the file system has been mounted, the valid bit is 0. If it has not been mounted, the valid bit is 1.
    Group Description: Record where this block started to be recorded;
  • Block bitmap: Record here whether that block has been used;
  • Inode bitmap: Record here whether the inode is used;
  • Inode table: Data storage area for each inode;
  • Data Blocks: Data storage area for each block.

The operation of linux file systemWe know that the access speed of the hard disk is relative to the memory It is very slow. In order to improve the overall speed, Linux adopts asynchronous processing.

What is asynchronous? For example: "When the system reads a certain file, the block data where the file is located will be loaded into the memory, so the disk block will be placed in the buffer cache area of ​​the main memory. If these When the data of the block is changed, initially only the block data of the main memory will be changed, and the block data in the buffer will be marked as "Dirty". At this time, the physical block of the disk has not been modified yet! Therefore, it means that the data of these "Dirty" blocks must be written back to the disk to maintain the consistency of the data on the physical blocks on the disk and the block data in the main memory. 』

So you really need to pay attention when shutting down Linux, otherwise it may cause file loss or even disk damage! ! !

mount point

So you really need to pay attention to the shutdown of Linux, otherwise it may cause the loss of files or even Disk damage! ! !

mount point

What we mentioned above is all about the file system, but it must be able to If we use our Linux, we have to "mount" it on our Linux system! We just mentioned above that the directory can record information related to file names and inodes. In addition, the directory also allows us to generate corresponding entry points to the filesystem. Therefore, we call that entry point directory "mount point (mount point)"

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of What does a linux file look like?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template