Linux File Types and extensions

Source: Internet
Author: User

We mentioned the concept that any device is a file in Linux. In addition, even interfaces for data communication are also the responsibility of exclusive files. Therefore, you will understand that there are many types of Linux Files. In addition to the-, D is the so-called general file and directory file, what types of files are there?

 

File Type

 

When introducing attributes, we mentioned that the front mark (D or-) can represent directories or files, that is, different file types. Linux has the following types of files:

 

• Regular file: This is the file we access. The first attribute displayed by LS-Al is [-], for example, [-rwxrwxrwx]. In addition, according to the file content, it can be roughly divided:

Plain text files (ASCII): This is the most common file type in Unix systems. It is called plain text files because the content contains data that can be directly read, such as numbers and letters. Almost all set files belong to this file type. For example, run the "cat ~" command ~ /. Bashrc "to see the content of the file (cat reads the file content ).

Binary: we mentioned in the history of GNU development that the system only recognizes and can execute binary files ). This format is used for executable files in Linux (script or text-based batch files are not counted. For example, the command cat is a binary file.

Data Files in Data Format: Some programs read files in specific formats during running. Files in specific formats can be called data files ). For example, when a user logs on to Linux, the logon data is recorded in the/var/log/wtmp file, which is a data file that can be read by the last command. But when cat is used, garbled characters are read. Because it belongs to a special format file.

• Directory: directory. The first attribute is [d], for example, [drwxrwxrwx].

• Link: similar to shortcuts in windows. The first attribute is [L], for example, [lrwxrwxrwx].

• Device and Device Files: files related to system peripherals and storage are usually concentrated in the/dev directory. There are two types:

Block Device Files: an interface device that stores data for system access. In short, it is a hard disk. For example, the Code of Hard Disk 1 is/dev/hda1 and other files. The first attribute is [B].

Character (character) Device File: The interface device of the serial port, such as the keyboard and mouse. The first attribute is [C].

• Sockets (sockets): these types of files are usually used for network data connections. We can start a program to listen to the requirements of the client, the client can communicate through the socket. The first attribute is [s], which is most often seen in the/var/run directory.

• Pipelines (PIPE): FIFO is also a special file type. It aims to solve errors caused by simultaneous access to a file by multiple programs. FIFO is the abbreviation of first-in-first-out. The first attribute is [p].

Then, using the "ls-Al" command, you can simply determine the type of the file by judging the first attribute of each file.

Except that the device file is a very important file in the system, it is best not to modify it at will (usually it won't let you modify it). Another interesting file is the connection file. If applications are often placed on the desktop, you should know that there is a "shortcut" under windows ". Similarly, Connection Files in Linux can be considered as shortcuts to files or directories. Sockets and MPs queue files are hard to understand, because they are closely related to processes. After learning about the processes (Chapter 1) in the future, come back and check them. In addition, you can view the system instructions through man FIFO and man socket.

Linux File Extension

Basically, a Linux file does not have a "extension". We know that whether a Linux file can be executed depends on the 10 attributes in the first column of the file and the file name. This is different from windows. In Windows, the file extensions that can be executed are usually ,. BAT and so on. In Linux, as long as the attribute contains x, for example, [-rwx-r-XR-x], this file can be executed.

However, the executable mode is different from the executable mode. For example, install. log in the root directory is a plain text file. Can this file be executed after the permission is changed to-rwxrwxrwx? Of course not. Because its content has no executable data at all. Therefore, X indicates that the file can be executed, but whether the file can be successfully executed depends on the content of the file.

Although the extension does not actually help, we still want to know what the file is, the file type is usually indicated by an appropriate extension. There are several common extensions:

• *. Sh: a batch processing file (scripts, script). Because the batch processing file is written in shell, the extension is compiled into. Sh.

• * Z, *. Tar, * .tar.gz, *. Zip, *. tgz: compressed file. This is because the compression software is gunzip, tar, and so on, according to different compression software and their related extensions.

• *. Html, *. php: webpage-related files, indicating the HTML syntax and PHP syntax respectively .. HTML files can be opened directly in a Web browser, while. php files can be viewed on the server through the browser of the client to obtain the webpage result after calculation.

 

In addition, there are programs such as Perl files whose extensions may also be. pl. Basically, the file name in Linux only helps you understand the possible usage of the file. The actual execution still requires attribute specifications. For example, although a file is an executable file, such as the famous proxy server software squid, if the attribute of this file is modified to unexecutable, it cannot be executed. This problem often occurs during file transfer. For example, you can download an executable file on the network, but it cannot be executed on your Linux system. That is, the file property may be changed. Upload files from the network to your Linux system. The file attributes are indeed changed.

 

In Linux, the file name of each file or directory can contain a maximum of 255 characters, and a full path can contain a maximum of 4096 characters, which is a fairly long file name. We hope that the Linux File name can be used to understand the role of the file at a glance, so the file name is usually very long, which is really difficult for people who are familiar with windows and cause low typing speed. However, we can only strengthen typing training. You will also know through the hotkeys in the previous chapter. In fact, you can press the [Tab] button to confirm the file name. This is useful. Of course, if you have read 3rd articles about Bash usage in this book, you will find that "variables are really quite useful ". I can't understand it. It doesn't matter. I'll talk about Bash in article 3rd.

 

Linux File Name restrictions

 

Generally, it is best to avoid special characters when setting the file name in Linux. For example:

* ? > < ; & ! [ ] | / ' " ` ( ) { } 

These symbols have special significance in the command line interface. In addition, when the file name starts with the decimal point ".", it indicates that the file is "hidden file ". At the same time, because parameters such as-option are often used in commands, it is best to avoid naming the names starting with-or.

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.