One Linux command per day: Linux file type and extension

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, directories file , character device files and the block device files, symbolic link files, etc. , now let's take 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):

command:  CAT ~/.BASHRC See the contents of the file.   (cat  is an instruction to read the contents of a file)

2>.  binary binary (binary):

linux in the executable file (scripts,   Text batch file does not count) is this format of file. using so 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 our Linux user logs on , the logged-in data is recorded in the/var/log/wtmp file, which is a data file that he can 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/tty

Crw-rw-rw-1 Root TTY 5, 0 11-03 15:11/dev/tty

[Email protected] ~]# ls-la/dev/sda1

Brw-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 seethat the properties of/dev/sda1 are 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 other devices.

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!

For example although there is a file for an executable file, such as a common/bin /ls This command that displays the file attributes, however, if the permissions of this file are modified to be unenforceable, then LS becomes unable to execute

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 are in the text Word interface, is a special meaning of the In addition, the beginning of the file name is the decimal point Span style= "Color:rgb (255,0,0); font-family: ' The song body '; font-size:14px;" > " " file At the same time, because of the command release, the  -option  and other options are often used,  so you'd better avoid naming the file name with  -  or  + 


This article is from the Linux Security Advisor blog, so be sure to keep this source http://chengyangyang.blog.51cto.com/9473151/1680904

One Linux command per day: Linux file type and extension

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.