Types of Linux Files

Source: Internet
Author: User

The type of file in Linux is defined by the first of the file permissions, and can be divided into the following categories.

1. Normal file

Common files include source program files, script files, executable program files, and various data files. The file type identification bit for ordinary files is "-" and the LS command allows you to view the file type, for example:

    1. #ls-L Suple
    2. -rw-r--r--1 root root 540 07-23 08:31 suple

2. Catalog files

A directory is actually a special kind of file. The directory can contain files and subdirectories. The type of the catalog file identifies the bit as "D", as follows:

    1. #ls-L TMP
    2. DRWXRWXRWT root root 4096 07-25 22:49 tmp

3. Socket file

Sockets are one of the common methods used for network communication. The Linux file system enables network communication through a socket file. The file type identification bit for the socket is "s", for example:

    1. #ls-L x1
    2. srwx------2 root root 0 07-25 17:49 x1

4. Named pipes

The file system enables interprocess communication through named pipe files. The file type of the named pipe is identified with a bit "P", for example:

    1. #ls-L P1
    2. prwx------2 root root 0 07-25 17:59 p1

5. Device files

The Linux system identifies the device as a special file for processing. Device files can be divided into two categories: character devices and block devices. The character device's file type identification bit is "C", and the printer, keyboard, and so on are all character devices. disks, tapes, and so on are all part of a block device, and the file type identification bit for the block device is "B". In the system's/dev directory, a large number of device files are stored, such as the character terminal tty1 device file is/dev/tty1. Using the LS command, you can see that the first character of the device is "C" and the first character of the block device is "B", as shown below:

    1. #ls-L/dev/tty1
    2. CRW-------1 root root 4, 1 07-25 05:44 tty1
    3. #ls-L/DEV/SDA1
    4. Brw-r-----1 Root Disk 8, 1 07-25 05:41 sda1

6. Link file

For ease of use, management, and disk space saving, Linux allows a physical file to have more than one logical name to create a linked file for a file that represents another name for the file. Different link files can be used to specify different access rights, which can be shared and safely controlled.

There are two types of linked files in the Linux file system: A class called a hard link, and a class of symbolic links. A hard-link file type identification bit is the same as the file being linked. Use the ln command without parameters to establish a hard-link file, such as a command to create a hard link to a SysV file, as follows:

    1. # Ls-il SysV
    2. 390162-rw-r--r--1 root root 0 07-26 00:51 SysV
    3. # ln SysV Syslink
    4. # Ls-il SysV slink
    5. 390162-rw-r--r--2 root root 0 07-26 00:51 slink
    6. 390162-rw-r--r--2 root root 0 07-26 00:51 SysV

From this example, we can see that the hard link file slink and the linked file SysV point to the same I node (node number 390162), the hard link with the linked file has the same file type identity bit "-", after establishing a hard link, the number of links to the file from 1 to 2.

In fact, hard links are just a hard copy of the source files, and their entry entries in the catalog file point to the same I node. This I node can be freed only if all links to the hard link are deleted. Any changes made to this file by the user, all hard links can be seen synchronously. Hard-linked files must be in the same file system, and directories cannot establish hard links.

To establish a symbolic connection, you can use the LN command with the parameter "-S", which simply specifies the access path to the actual file, unlike the I node number of the source file. If the source file is deleted, the symbolic link is corrupted. The file type identification bit for the symbolic link is "l". For example, to establish symbolic link fuser for file ftpuser, the command is as follows:

  1. # Ls-il Ftpuser
  2. 390161-rw-r--r--1 root root 0 07-26 01:17 ftpuser
  3. # ln-s Ftpuser Fuser
  4. # Ls-il Ftpuser Fuser
  5. 390161-rw-r--r--1 root root 0 07-26 01:17 ftpuser
  6. 390162 lrwxrwxrwx 1 root root 7 07-26 01:18 fuser-> Ftpuser
  7. # RM Ftpuser
  8. RM: Do you want to delete the generic empty file "Ftpuser"? Y
  9. # Ls-il Ftpuser Fuser
  10. Ls:ftpuser: No file or directory
  11. 390162 lrwxrwxrwx 1 root root 7 07-26 01:18 fuser-> Ftpuser

You can see that the ftpuser is different from the I node number of Fuser (Ftpuser is 390161,fuser to 390162) and the file type of Fuser is "L". When the source file Ftpuser is deleted, the symbolic link file is an error.

Unlike hard links, symbolic links can be established across file systems and can be specified to a directory. The difference between a hard link and a symbolic link is shown in 6.3.

Figure 6.3 Hard links and symbolic links

Types of Linux Files

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.