Linux File System Overview, linux File Overview

Source: Internet
Author: User

Linux File System Overview, linux File Overview

Unix files are information carriers (container) consisting of byte sequences. The kernel does not interpret the file content.

A file in a Linux File System is a collection of data. The file system not only contains data in the file but also has a system structure, all files, directories, soft links, and file protection information seen by Linux users and programs are stored in the file.

Linux's earliest file system was Minux, but the file system specifically designed for Linux-the extended File System Version 2 (EXT2) was designed and added to Linux, this has a major impact on Linux.

Common Linux File Systems
  • Ext2: ext2 upgrade version ext3 is the default file system in Linux

  • Swap: Used as a swap partition.

  • Vfat: compatible with Windows operating systems, mainly FAT16 and FAT32

  • NFS: The Network File System is a unique feature of Linux. It facilitates file sharing in the LAN and allows multiple hosts to share the file system of one host.

Hard link and soft link

Command Format:

$ ln P1 P2

Create a new hard link. That is, create a hard link named P2 for the file identified by path P1.

There are two restrictions on hard links
  • You are not allowed to create hard links for directories. Because this may change the directory tree into a ring tree, it is impossible to locate a file by name.

  • A link can be created only between files in the same file system. This imposes a large limit because modern Unix systems may contain multiple file systems that are located on different disks and/or partitions, and users cannot know the physical division between them.

Soft link [symbolic link]

A symbolic link is a short file that contains any path name of another file. A path name can point to any file or directory in any file system, or even to a non-existent file.

Command Format:

$ ln -s P1 P2

Create a new soft link with the path name P2. P2 points to the path P1.

Linux directory structure

The Linux File System adopts a hierarchical tree directory structure. The top layer of the structure is the root directory "/", and other directories are created under the root directory.

The file or directory name consists of any ASCII character sequence except the "/" and the null character "\ 0" (some operating systems allow multiple characters to represent the file name at your own discretion, such as Unicode ). Most file systems have limits on the file name length. Generally, the length cannot exceed 255 characters.

In Linux, no matter how many disk partitions are managed by the operating system, such a directory tree has only one. In terms of structure, tree directories on disk partitions are not necessarily tied.

Functions of common Directories
  • /Root directory

  • /Bin command to save the directory (commands that can be read by common Users)

  • /Boot startup directory, start Related Files

  • /Dev device file storage directory

  • /Etc configuration file storage directory

  • /Home: home Directory of common users

  • /Lib system library save directory

  • /Mnt system mount directory

  • /Media Mount directory

  • /Root super user's home directory

  • /Tmp temporary directory

  • /Sbin command to save the directory (the directory that super users can use)

  • /Proc directly writes data to the memory

  • /Sys

  • /Usr System Software Resource Directory

    /Usr/bin system command (Common User)
    /Usr/sbin System Command (superuser)
    /Usr/include: standard header file
    /Usr/src: kernel source code
  • /Var System Documentation

The bin and sbin in the root directory, bin and sbin In the usr directory are used to save system commands.

The proc and sys directories cannot be operated directly. These two directories store the memory overload points.

Linux File Type
  • Common File: it is usually a streaming file.

    [root@AmorLei tmp]# ls -lh yan.test-rw-r--r-- 1 root root 13 Sep 22 15:05 yan.test
  • Directory file: Used to indicate and manage all files in the system

    [root@AmorLei tmp]# ls -lhdrwxr-xr-x 2 root root 4.0K Sep 26 12:20 yanlei
  • Linked file: used to share files in different directories

    [root@AmorLei tmp]# ls -lh yan.softlinklrwxrwxrwx 1 root root 8 Sep 26 12:26 yan.softlink -> yan.test
  • Device Files: including block device files and character Device Files

    B Indicates a block device, and c indicates a character device.

    [root@AmorLei /]# ls -la /dev/ttycrw-rw-rw- 1 root tty 5, 0 Sep 15 20:35 /dev/tty
  • Pipe (FIFO) files: a method for inter-process communication


  • Socket file: the file type is related to network communication.

    [root@AmorLei /]# ls -lh /var/lib/mysql/mysql.socksrwxrwxrwx 1 mysql mysql 0 Sep 26 12:20 /var/lib/mysql/mysql.sock
File descriptor and index Node

Unix clearly distinguishes the content of a file from the description file. In addition to device files and special file system files, each file consists of character sequences.

All the information required by the file system to process files is contained in a data structure named inode. Each file has its own index node, which is used by the file system to identify the file.

The file system provides at least the following attributes specified in the POSIX standard:

  • File Type

  • Number of hard links related to files

  • File length in bytes

  • Device identifier

  • Indicates the index node number of a file in the file system.

  • UID of the file owner

  • User Group ID of the file

  • Timestamps indicate the time when the status of the index node changes, and the last access time is the last modification time.

  • Access permission and file Mode

Access permission and file Mode

There are three types of potential users of Files

  • User who is the file owner

  • Users in the same group, excluding owners

  • All remaining users (Others)

There are three types of access permissions: read, write, and execute. Each group of users has these three permissions.

Partition

In Windows, the physical address is separated first, and then the directory is created on the partition. In Windows, all paths start with the drive letter, for example, C: \ Program file.

The opposite is true for Linux, where a directory is first available and then the physical address is mapped to the directory. In Linux, all paths start from the root directory. Linux is divided into three partitions by default, namely the boot partition, the swap partition, and the root partition.

Mount

Partitions in Linux need to be mounted to a directory before they can be used. The significance of mounting is to put the content of the disk partition in a directory. The process of attaching a directory and a partition is called Mount, and the location of the mounted directory in the file tree is the Mount point.

When you want to use a device, for example, to read a formatted partition, CD, or software in the hard disk, you must first map these devices to a directory, this directory is called "mount point". In this way, you can read these devices and block the details of physical partitions. Users only have a unified logical concept, everything is a file.

References:

Deep understanding of Linux kernel Daniel P. Bovet & Marco Cesati

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.