What does a linux file look like?

Nov 09, 2022 pm 07:54 PM
linux

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

vscode terminal usage tutorial vscode terminal usage tutorial Apr 15, 2025 pm 10:09 PM

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

Where to write code in vscode Where to write code in vscode Apr 15, 2025 pm 09:54 PM

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

vscode terminal command cannot be used vscode terminal command cannot be used Apr 15, 2025 pm 10:03 PM

Causes and solutions for the VS Code terminal commands not available: The necessary tools are not installed (Windows: WSL; macOS: Xcode command line tools) Path configuration is wrong (add executable files to PATH environment variables) Permission issues (run VS Code as administrator) Firewall or proxy restrictions (check settings, unrestrictions) Terminal settings are incorrect (enable use of external terminals) VS Code installation is corrupt (reinstall or update) Terminal configuration is incompatible (try different terminal types or commands) Specific environment variables are missing (set necessary environment variables)

See all articles