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.
#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.
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.
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 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:
- 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.
- 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! ! !
So you really need to pay attention to the shutdown of Linux, otherwise it may cause the loss of files or even Disk damage! ! !
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!

The five core components of the Linux operating system are: 1. Kernel, 2. System libraries, 3. System tools, 4. System services, 5. File system. These components work together to ensure the stable and efficient operation of the system, and together form a powerful and flexible operating system.

The five core elements of Linux are: 1. Kernel, 2. Command line interface, 3. File system, 4. Package management, 5. Community and open source. Together, these elements define the nature and functionality of Linux.

Linux user management and security can be achieved through the following steps: 1. Create users and groups, using commands such as sudouseradd-m-gdevelopers-s/bin/bashjohn. 2. Bulkly create users and set password policies, using the for loop and chpasswd commands. 3. Check and fix common errors, home directory and shell settings. 4. Implement best practices such as strong cryptographic policies, regular audits and the principle of minimum authority. 5. Optimize performance, use sudo and adjust PAM module configuration. Through these methods, users can be effectively managed and system security can be improved.

The core operations of Linux file system and process management include file system management and process control. 1) File system operations include creating, deleting, copying and moving files or directories, using commands such as mkdir, rmdir, cp and mv. 2) Process management involves starting, monitoring and killing processes, using commands such as ./my_script.sh&, top and kill.

Shell scripts are powerful tools for automated execution of commands in Linux systems. 1) The shell script executes commands line by line through the interpreter to process variable substitution and conditional judgment. 2) The basic usage includes backup operations, such as using the tar command to back up the directory. 3) Advanced usage involves the use of functions and case statements to manage services. 4) Debugging skills include using set-x to enable debugging mode and set-e to exit when the command fails. 5) Performance optimization is recommended to avoid subshells, use arrays and optimization loops.

Linux is a Unix-based multi-user, multi-tasking operating system that emphasizes simplicity, modularity and openness. Its core functions include: file system: organized in a tree structure, supports multiple file systems such as ext4, XFS, Btrfs, and use df-T to view file system types. Process management: View the process through the ps command, manage the process using PID, involving priority settings and signal processing. Network configuration: Flexible setting of IP addresses and managing network services, and use sudoipaddradd to configure IP. These features are applied in real-life operations through basic commands and advanced script automation, improving efficiency and reducing errors.

The methods to enter Linux maintenance mode include: 1. Edit the GRUB configuration file, add "single" or "1" parameters and update the GRUB configuration; 2. Edit the startup parameters in the GRUB menu, add "single" or "1". Exit maintenance mode only requires restarting the system. With these steps, you can quickly enter maintenance mode when needed and exit safely, ensuring system stability and security.

The core components of Linux include kernel, shell, file system, process management and memory management. 1) Kernel management system resources, 2) shell provides user interaction interface, 3) file system supports multiple formats, 4) Process management is implemented through system calls such as fork, and 5) memory management uses virtual memory technology.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver Mac version
Visual web development tools
