File types for Linux

Source: Internet
Author: User

Linux files are usually divided into 7 major categories

File type Abbreviation English name
Normal file - Regular file
Catalog files D Directory file
Block device files B Block Special File
Character device files C Character Special File
Named pipe files F FIFO or named pipe
Socket file S Socket
Symbolic Link File L Symbolic link

Normal file

Ordinary files are the most common type of files in Linux system, which is characterized by not including the structure information of the file system, which can include graphic files, data files, document files, sound files, etc. according to the internal structure can be divided into text files and binary files two kinds.

    • Text file

A text file is a character (ASCII code) consisting of a file that stores a file with information about the basic structure of the behavior, and its contents are data that the user can read directly, such as numbers, letters, and so on. Typically, Linux's system configuration files are basically this type of file and can be viewed directly using the Cat command.

    • binary files

A binary file is a file that is represented in an in-memory format, usually not viewed directly, and must be viewed using the appropriate software. In general, the executable files in Linux (scripts, text-based batch files are not counted) basically belong to this type of file and can be run.

Catalog files

A directory in Linux is also a file, known as a directory file, which is a file system in a directory contains a directory of items composed of files, users can read but not modify the contents of the directory file, only allow the system to modify.

Device files and block device files

Linux regards devices (such as hard disks, serial ports, etc.) as files, with the same method of operation, which is a documented device file, a file used by the operating system to provide a connection to an I/O device, which is divided into character device files and block device files, which are usually stored in the dev directory.

Character device files

This is a sequential data flow device file that reads and writes the files by character, and these characters are continuously forming a stream of data. Character devices do not have buffers, so the reading and writing of this device is real-time, such as serial terminal, tape drive and so on.

Block device files

This is a certain structure of the subsequent access to the device file, read and write to this device is a block, it uses a buffer to hold the temporary data, waiting for the condition to mature, from the cache once written to the device, or from the device once read out into the buffer, such as disk and file system.

Named pipe files

Named pipe files are also known as FIFO files, which are primarily used to pass data between Linux processes and are a communication mechanism between Linux processes. A pipeline is a "medium" that passes data between processes, one process writes data to the end of the pipeline, and another process reads data from the other end of the pipeline. Typically, pipelines are built into the cache. The data is processed by the first-in-one rule. Pipeline files can be divided into famous pipes and nameless pipes two kinds.

Socket file

Socket (socket) files are mainly used for communication between processes of different computers, which is a data structure in the kernel of the operating system, which is the portal of communication between nodes in the network. There are three types of sockets: Streaming sockets, datagram sockets, and raw sockets. A streaming socket is also a TCP socket (or a connection-oriented socket), which is a UDP socket (or a non-connected socket), and the original socket is represented by "Sock_raw".

    • Flow sockets Define a reliable connection-oriented service for error-free, repeatable sequential data transfer
    • Datagram sockets define a non-connected service that transmits data through separate messages that are unordered and not guaranteed to be reliable and error-free.
    • Raw sockets allow access to low-level protocols such as IP or ICMP, primarily for testing new network protocols, etc.

Symbolic Link File

Also known as the link file, is a special kind of file, is actually pointing to a real file link. A linked file provides a way to share files that are not shared by file names in a linked file, but rather through a pointer to a file that is included in the linked file to enable access to the file. A normal user can create a linked file and access the file it points to by its pointer. Use linked files to access normal files, as well as to access catalog files and other files that do not have normal file patterns. In other words, linked files can establish a link between different file systems. Depending on the linked object, you can divide it into hard-link files and symbolic link files.

Linux files are a simple sequence of byte data, so the structure and access methods for text files, binaries are the same under Linux. Linux files consist of a series of blocks, each of which may contain 512, 1024, 2048, or 4,096 bytes, which is determined by the system implementation, and the block size is the same in the same file system. When using a larger block, because each disk operation can transfer more data, the operation of less events, it can improve the data transfer between disk and memory, but relative, because the block is too large, the effective capacity of the storage will be reduced, which means that some storage space is wasted.

Linux uses file descriptors (files descriptor) to identify specific files that a process is accessing, and when a file is opened or a file is created, Linux returns a file descriptor for other actions to refer to, usually a small non-negative integer for the file descriptor.

Linux, each process can have up to 1024 file descriptors, and has its own file descriptor, where the first three of the general process is fixed, and is automatically opened by the system:

    • File descriptor 0: Standard input file, usually corresponding to keyboard light input device
    • File descriptor 1: Standard output file, usually corresponding to display device
    • File descriptor 2: standard error output file, usually corresponding display device

For the above three file descriptors, the user program does not have to perform the file open operation can be used directly, its definition in the header file section is as follows:

1 #define    Stdin_fileno      02#define    stdout_fileno     13#define    stderr_ Fileno     2

File types for Linux

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.