A file is a collection of related information with a name, and the exact definition of a file in a Linux system is a character stream that does not contain any other structure. In layman's parlance, there is no other relationship between characters and characters in a file except that they belong to a file. The relationship between characters in a file is created and interpreted by the application that uses the file.
Each file has a specific attribute. The file properties of Linux systems are more complex, including file type and file permissions in two aspects.
1. File type
The files under Linux can be divided into 5 different types. They are normal files, directory files, linked files, device files, and piping files. Here is a detailed description of them.
(1) Ordinary documents
Ordinary documents, also known as regular documents, are the most common type of file, but also the most commonly used type of file. The feature is that it does not contain the structure information of the file system. Commonly used files, including graphics files, data files, document files, sound files, and so on are common files. This type of file is subdivided into two file types by its internal structure: a text file and a binary file.
Text files: Text files are represented by characters (usually ASCII code) and are stored in the form of information that behaves as a basic structure.
Binary files: Binaries are represented in the form of information in memory, which is not usually viewed directly, but must be used by the appropriate software.
(2) directory files
A catalog file is a file that holds the file name and its associated information. is the basic node of the kernel organization file system. The catalog file can contain the next level of directory files or normal files.
Note: In Linux, the catalog file is a file. But Linux directory files and other operating systems in the "directory" concept is different, it is a Linux file. Of course, in actual use can also not carefully distinguish between these two statements, even in the specific narrative of this book, sometimes referred to directory files as a directory, but pay attention to their conceptual differences.
(3) Link file
A linked file is a special file. It is actually a link to a real-life file. For example, when a user wants to use a file from another directory file in a directory file, it does not need to replicate it, but simply create a link file in this directory to point to the file being called. When used specifically, they don't feel any different. Depending on the linked object, the linked file can be subdivided into hard linked files and symbolic link files.
(4) Equipment files
The device file is the most specific file in Linux. Because of its existence, the Linux system makes it easy to access the external devices. The Linux system provides a standard interface for external devices and treats external devices as a special kind of file. Users can access external devices like normal files. This makes it easy for Linux systems to adapt to the evolving external devices. Usually the Linux system places the device files in the/dev directory. The device file specifies an external device by using the device's primary and secondary device numbers. The main unit number is used to describe the device type, and the secondary device number is used to describe the specific equipment. For example, with an IDE hard disk as the first main disk, the device file for the third partition is/dev/hda3. Where HD is the main device number, A3 is the secondary device number. Depending on how the data is accessed, the device files can be subdivided into two types: block device files and character device files.
Block device files: Block device files Access data in a fixed-length block.
Character device files: A character device file accesses data in a specified character (usually a character).
Most external devices offer two ways to access them. But for each device, it has the best way to access it.
Note: There is a very special file/dev/null in the device file. All data placed in this device will no longer exist.
It can be viewed as a delete operation.
(5) Pipeline file
Piping files are also a very special kind of file. Mainly used for information transfer between different processes. When data or information transfer is required between two processes, it is possible to pass through a piping file. A process writes data or information that needs to be passed to one end of the pipe, and another process obtains the required data or information from the other end of the pipe. Typically, pipelines are built into the cache. Use the FIFO rule to process the data. It can be subdivided into two kinds of famous pipes and nameless pipes.
2. File permissions
Linux system is a typical multi-user system, different users are in different positions. To protect the security of the system, the Linux system makes different rules for different users to access the same file. For a file in a Linux system, its permissions can be divided into three types: Read permissions, write permissions, and execute permissions. Represented by R, W, and X respectively. Different users have different read, write, and execute permissions. For a file, it has a specific owner, which is the user who owns the file. Also, because in a Linux system, users are grouped by group, and one user belongs to one or more groups. Therefore, users other than the owner of the file can be divided into the same group of users and other users of the file owner. The Linux system therefore provides different file access rights for file owners, file owners, and three classes of users and other users.
Note: The system administrator root user is a very special user who has the highest control over the system. For all files in the system root user has read, write, and execute permissions.
View a full set of articles: Http://www.bianceng.cn/Programming/C/201212/34807.htm