File types and extensions in Linux

Source: Internet
Author: User
This article describes in detail the file types and file extensions in Linux. It provides detailed descriptions of each file type and the file suffix. For more information, see

Linux file types and Linux file names represent two different concepts. Similar to file.txt1_file.tar.gz created by a general application, although these files must be opened in different programs, most of them are normal files (also known as common files) that are measured in Linux file types ).

I. file type

Common types of Linux files include common files, directory files, character device files, block device files, and symbolic link files.

1. Common Files

We use ls-lh to view the attributes of a file. we can see that there is a file like-rwxrwxrwx. it is worth noting that the first symbol is-. such a file is a common file in Linux. These files are generally created using related applications, such as tools, document tools, archiving tools... or cp tools. To delete such files, run the rm command. In addition, according to the content of the file, it can be divided:

1>. plain text file (ASCII ):

This is the most common file type in Linux. it is called a plain text file because the content is the data that we humans can directly read, such as numbers and letters. Almost all files that can be used as a set belong to this file type. For example, you can use the command: cat ~ /. Bashrc to view the content of the file. (Cat is a command to read the content of a file ).

2>. binary file (binary ):

Linux systems only know and can execute binary files ). In Linux, executable files (scripts, text-type batch files are not counted) are in this format. The command cat is a binary file.

3>. data ): 

Some programs read files in certain formats during operation. files in specific formats can be called data files ). For example, when a user logs on to Linux, the login data is recorded in the/var/log/wtmp file, which is a data file, he can read it through the last command! But when cat is used, garbled characters are read ~ Is it a special format file?

2. Directory files

When we run the command in a directory, we can see a file like drwxr-xr-x, which is a directory. The directory is a special file in Linux. Note that its first character is d. Run mkdir or cp to create a directory. cp can copy one directory to another. Delete the file by using the rm or rmdir command.

3. character device or block device file

If you enter the/dev directory and list the files, you will see something similar to the following:


Copy codeThe code is as follows:
[Root @ localhost ~] # Ls-al/dev/tty

Crw-rw-1 root tty 5, 0 11-03/dev/tty

[Root @ localhost ~] # Ls-la/dev/sda1

Brw-r ----- 1 root disk 8, 1 11-03 07:11/dev/sda1

We can see that the attribute of/dev/tty is crw-rw-. Note that the first character is c, which indicates the character device file. For example, serial devices such as cats. We can see that the attribute of/dev/sda1 is brw-r -----. Note that the first character is B, which indicates a device, such as a hard disk or a optical drive.

Files of this type are created using mknode and deleted using rm. Currently, in the latest Linux release, we generally do not need to create device files on our own. Because these files are associated with the kernel.

Files related to the system perimeter and storage are usually stored under the/dev directory! There are two types:

Block device files:

It refers to some interface devices that store data to provide random access to the system. for example, hard disks and floppy disks are the same! You can randomly read and write data in different blocks of the hard disk. this device is a group of devices! You can check/dev/sda and the first attribute is [B].

Character (character) device file:

It is also an interface device for some serial ports, such as the keyboard and mouse! These devices feature a one-time read and cannot be truncated. For example, you cannot let the mouse jump to another screen, but slide to another place! The first attribute is [c].

4. data interface file (sockets ):

Data interface file (or: set interface file), this type of file is usually used on the network to undertake the data. We can start a program to listen to the requirements of the client, and the client can communicate data through this socket. The first attribute is [s], which is most often seen in the/var/run directory.

For example, when we start the MySQL server, a mysql. sock file is generated.


Copy codeThe code is as follows:
[Root @ localhost ~] # Ls-lh/var/lib/mysql. sock

Srwxrwxrwx 1 mysql 0 04-19 11: 12/var/lib/mysql. sock

Note that the first character of the attribute of this file is s.

5. symbolic link file: 

When viewing the file attributes, we will see lrwxrwxrwx. Note that the first character is l, and this type of file is a link file. Is a new file name through the ln-s source file name. The preceding example shows that setup. log is a soft link file of install. log. How can this problem be solved? This is similar to shortcuts in Windows.

Example of creating a symbolic link file:


Copy codeThe code is as follows:
[Root @ localhost test] # ls-lh log2012.log

-Rw-r -- 1 root 296 K 11-13 06:03 log2012.log

[Root @ localhost test] # ln-s log2012.log linklog. log

[Root @ localhost test] # ls-lh *. log

Lrwxrwxrwx 1 root 11 11-22 linklog. log-> log2012.log

-Rw-r -- 1 root 296 K 11-13 06:03 log2012.log

6. Data Transmission File (FIFO, pipe ):

FIFO is also a special file type. it aims to solve the problem of simultaneous access to a file by multiple programs. FIFO is the abbreviation of first-in-first-out. The first attribute is [p].

II. Linux file extension

1. extension type

Basically, a Linux file does not have a so-called extension. whether a Linux file can be executed depends on the ten attributes in the first column of the file, and does not have any relationship with the file name. This concept is different from that of Windows! In Windows, the file extension that can be executed is usually. com. exe. bat and so on. in Linux, if you have x in your permissions, for example, [-rwx-r-xr-x] indicates that the file can be executed.

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

Even so, we still want to know what the file is by using the extension. Therefore, we usually use an appropriate extension to indicate the type of the file. There are several common extensions:

*. Sh: script or batch processing file (scripts). because the batch processing file is written in shell, the extension is compiled into. sh.

* Z, *. tar, * .tar.gz, *. zip, *. tgz: compressed files that have been packaged. This is because the compression software is gunzip, tar, and so on. because of the different compression software, the related extension is used!

*. Html, *. php: webpage-related files, which respectively represent the HTML syntax and PHP syntax. The. html file can be directly opened in a web browser. for the. php file, you can browse it on the server through the client browser to obtain the webpage result after calculation.

Basically, the file name on the Linux system really only helps you understand the possible usage of the file. the actual execution or failure still requires the permission specification. For example, although a file is an executable file, such as the common command/bin/ls to display file attributes, if the permission of this file is changed to unexecutable, then ls becomes unexecutable.

This problem occurs most often during file transfer. For example, you can download an executable file on the network, but it cannot be executed on your Linux system! Haha! This means that the attributes of the file may be changed. Do not doubt that the attributes and permissions of files uploaded from the network to your Linux system will indeed be changed.

2. Linux file name length limit:

In Linux, when the preset Ext2/Ext3 file system is used, the file name length limit is:

The maximum file name allowed for a single file or directory is 255 characters

The full path name and directory (/) are 4096 characters long

Is a long file name! We hope that the Linux file name can be viewed at a glance, so the file name is usually very long.

3. Linux file name character restrictions:

Since Linux has some command operation relationships under the text interface, it is recommended that you avoid special characters when setting the file name under Linux! For example:

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

These symbols are of special significance in the text interface. In addition, when the file name starts with the decimal point ".", it indicates that this file is a hidden file! At the same time, because the options such as-option are often used in command issuing, it is recommended that you also avoid naming the beginning of the file name with "-" or "+.

Related Article

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.