One Linux command per day: Linux file types and extensions

Source: Internet
Author: User

The Linux file type and the name of the Linux file represent the meanings of two different concepts. We create through general applications such as File.txt, file.tar.gz, these files, although to be opened with different programs, but in the Linux file type measurement, mostly regular files (also known as ordinary files).

I. File type

Common to Linux file types are: Normal files, directory files, character device files and block device files, symbolic link files, and so on, now we have a brief description.

1. Common Files

We use LS-LH to see the properties of a file, we can see similar-rwxrwxrwx, it is worth noting that the first symbol is-, such a file in Linux is a normal file. These files are typically created with some related applications, like tools, document tools, archive tools .... or CP tools. This type of file is deleted using the RM command. In addition, according to the contents of the document, but also can be divided into:

1>. Plain text file (ASCII):

This is the most common type of file in a Linux system, known as a plain text file because the content is data that we humans can read directly, such as numbers, letters, and so on. Almost as long as we can use it as a set of files belongs to this file type. For example, you can use the command: Cat ~/.BASHRC to see the contents of the file. (Cat is an instruction to read the contents of a file).

2>. binary file (binary):

Linux systems are only known and can execute binaries (binary file). Executable files in Linux (scripts, text-based batch files are not counted) are files in this format. The command you just used, cat, is a binary file.

3>. data Format File:

Some programs read files in certain formats while they are in operation, and those files in a particular format can be referred to as data files. For example, when a user logs on, our Linux logs the logged-in data in the/var/log/wtmp file, which is a data file that can be read through the last command! But when using cat, it reads garbled ~ because he belongs to a file in a special format?

2. Catalog files

When we execute in a directory, see similar drwxr-xr-x, such files are directories, directories in Linux is a more special file. Note that its first character is d. The command to create a directory can be used with the mkdir command, or the CP command, where CP can copy a directory to another directory. Remove 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 like this:

[[email protected] ~]# ls-al/dev/ttycrw-rw-rw-1 root TTY 5, 0 11-03 15:11/dev/tty[[email protected] ~]# LS-LA/DEV/SD A1brw-r-----1 Root Disk 8, 1 11-03 07:11/dev/sda1

We see that the/dev/tty property is crw-rw-rw-, note that the first character in front is C, which represents the character device file. such as the cat and other serial devices. We see that the/dev/sda1 property is the brw-r-----, note that the first character in front is B, which indicates a block device, such as a hard disk, an optical drive, and so on.

This kind of file is created with Mknode and deleted with RM. Currently in the latest Linux distributions, we generally do not have to create the device files ourselves. Because these files are associated with the kernel.

Some files related to the perimeter and storage of the system are usually concentrated in the/dev directory! It is usually divided into two types:

block (block) device file :

is some storage data to provide system random access to the interface device, for example, hard disk and floppy disk and so on! You can read and write randomly in different chunks of the hard drive, which is a group device! You can check the/DEV/SDA yourself, and you'll find the first property is [b]!

Character (character) device file:

That is, some serial port interface devices, such as keyboards, mice and so on! These devices feature a one-time read and cannot truncate the output. For example, you can't let the mouse jump to another screen, but slide to another place! The first property is [C].

4. Data interface file (sockets):

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

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

[Email protected] ~]# Ls-lh/var/lib/mysql/mysql.sock

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

Note that the first character of the property of this file is S.

5. Symbolic Link File :

When we look at the properties of a file, we see something like lrwxrwxrwx, note that the first character is L, and this type of file is a linked file. is the new file name by ln-s the source file name. Above is an example that indicates that Setup.log is a soft link file for Install.log. How do you understand it? This is somewhat similar to the shortcuts in the Windows operating system.

Example of how to create a symbolic link file:

[Email protected] test]# LS-LH Log2012.log

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

[Email protected] test]# ln-s log2012.log linklog.log

[Email protected] test]# LS-LH *.log

lrwxrwxrwx 1 root root one 11-22 06:58 linklog.log log2012.log

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

6. Data transfer file (Fifo,pipe):

FIFO is also a special type of file, and his main purpose is to solve the error caused by multiple programs accessing a file simultaneously. FIFO is the abbreviation for first-in-first-out. The first property is [P].

Two. linux file name extension

1. Extension type

Basically, the Linux file is not the so-called extension, a Linux file can be executed, and his first column of the 10 attributes, and the file name has no relationship at all. This concept is not the same as the Windows situation! Under Windows, the file name extensions that can be executed are usually. com. exe. bat and so on, and under Linux, as long as you have x in your permission, for example [-rwx-r-xr-x] means that the file can be executed.

However, can be executed and can be executed is not the same as the success of ~ For example, in the root directory of the Install.log is a plain text file, if through the modification of the permission to become-rwxrwxrwx, this file can really execute success? Of course not ~ because his content simply does not have the data that can be executed. So, this x represents the ability of the file to execute, but if it succeeds, it will have to look at the contents of the file.

Nevertheless, we still want to be able to understand what the file is by extension, so we will usually indicate what kind of file it is with the appropriate extension. There are several common extensions at the bottom:

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

*z, *.tar, *.tar.gz, *.zip, *.tgz: Packaged compressed files. This is because the compression software is gunzip, tar and so on, due to different compression software, and take its associated extension!

*.html, *.php: Web-related files, respectively, representing HTML syntax and PHP syntax of the Web page file. html files can be opened directly using a Web browser, as for. php files can be accessed through the client browser to the server side to get the operation Page results.

Basically, a file name on a Linux system really just lets you know what the file might be used for, and the actual execution will still require permission specifications. For example, although there is a file for an executable file, such as the common/bin/ls directive that displays the file attributes, if the permissions of this file are modified to be unenforceable, then LS becomes unenforceable.

The above problems occur most often in the process of file transfer. For example, you download an executable file on the network, but it just can't be done on your Linux system! Oh! Then it is possible that the properties of the file have been changed. Do not suspect that the properties and permissions of a file are actually changed from the network to your Linux system.

2. linux file name length limit :

Under Linux, when using the preset ext2/ext3 file system, the filename length is limited to:

Maximum allowable file name of a single file or directory is 255 characters

Full path name and table of contents (/) with full file name of 4,096 characters

It's quite a long file name! We want the file name of Linux to know what it is doing at a glance, so the filename is usually very long.

3. Limitations of characters for Linux filenames :

Because of the Linux in the text interface some of the instructions to operate the relationship, in general, you set the name of Linux under the file, it is best to avoid some special characters better! For example under these:

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

Because these symbols in the text interface, there is a special meaning. Additionally, the file name begins with the decimal point "." When, represent this file as hidden file! At the same time, as the command is released, you will often use options such as-option, so you should also avoid naming the file name at the beginning of-or +.

One Linux command per day: Linux file types and extensions

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.