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:
- #ls-L Suple
- -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:
- #ls-L TMP
- 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:
- #ls-L x1
- 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:
- #ls-L P1
- 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:
- #ls-L/dev/tty1
- CRW-------1 root root 4, 1 07-25 05:44 tty1
- #ls-L/DEV/SDA1
- 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:
- # Ls-il SysV
- 390162-rw-r--r--1 root root 0 07-26 00:51 SysV
- # ln SysV Syslink
- # Ls-il SysV slink
- 390162-rw-r--r--2 root root 0 07-26 00:51 slink
- 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:
- # Ls-il Ftpuser
- 390161-rw-r--r--1 root root 0 07-26 01:17 ftpuser
- # ln-s Ftpuser Fuser
- # Ls-il Ftpuser Fuser
- 390161-rw-r--r--1 root root 0 07-26 01:17 ftpuser
- 390162 lrwxrwxrwx 1 root root 7 07-26 01:18 fuser-> Ftpuser
- # RM Ftpuser
- RM: Do you want to delete the generic empty file "Ftpuser"? Y
- # Ls-il Ftpuser Fuser
- Ls:ftpuser: No file or directory
- 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