What are the basic file types in Linux?

青灯夜游
Release: 2023-04-10 16:44:33
Original
16206 people have browsed it

There are 5 basic file types in Linux: 1. Ordinary files, which refer to files that do not contain structural information of file system information and are files that users come into contact with; 2. Directory files, which are used for Files that store file names and related information can include lower-level file directories or ordinary files, and are the basic nodes of the kernel organization file system; 3. Link files point to a real file link; 4. Device files, the role It is to access external devices; 5. Pipe files are used to transfer information between different processes.

What are the basic file types in Linux?

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

Everything in Linux is a file, and there are many types of files. Use the ls -l command to view the properties of the file. The first character in the first column of the displayed result is Indicate the file type of the file, as follows:

1. Ordinary file

Ordinary file in Linux It refers to files that do not contain structural information of file system information, and are files that users come into contact with, such as data files, document files, audio files, etc.

After using the ls -l command, the files whose first character in the first column is "-" are ordinary files. As shown in the figure above, ordinary files are generally in gray font, and those in green font are executable files. The ones in red font are compressed files.

File permissions:

Taking an ordinary file as an example, use the ls -l command. You can see that the first column of the result is -rwxrwxrwx## In the form of #, the first character "-" indicates that the file is a normal file. It can also be other characters. Different characters represent different types of files. The following string of characters indicates the permissions of the file, among which:

1) r indicates that the file has readable permissions. If the position is "-", it indicates that the file is unreadable;

2) w indicates that the file has write permission. If the position is "-", it indicates that the file is not writable;

3) x indicates that the file has executable permission. If the position is "-" , indicating that the file does not have executable permissions;

4) The first rwx represents the permissions of the owner of the file on the file; the second rwx represents the permissions of the group to which the file belongs; The three rwx represent other users' permissions on the file.

Create a normal file:

You can use the touch command to create a file:

touch newfile
Copy after login

Delete one Ordinary file:

You can use the rm command to delete a file:

rm newfile
Copy after login

2. Directory file

Directories in Linux are also files. Directory files in Linux are files used to store file names and related information. They can contain lower-level file directories or ordinary files. They are the basic nodes of the kernel organization file system.

The directory file stores information such as the inode number and file name of other files in the directory. Each data item in the directory file is a link to the inode number of a certain file. Deleting the file name is equivalent to deleting it. The corresponding link. The font color of the directory file is blue. Use the ls -l command to view it. The first character is "d" (directory).

Permissions of directory files:

1) r indicates that the directory file has readable permissions, that is, you can use the ls command to view the storage status of the directory;

2) w indicates that the directory file has write permission, which means you can add, modify, and delete files in the directory;

3) x indicates that the directory file has executable files, that is, you can use the cd command Go to this directory.

You can use the

chmod command to change file permissions.

Create a directory:

You can use the mkdir command to create a directory file:

mkdir directory
Copy after login

Delete one Directory:

You can use the rmdir command to delete an empty directory:

rmdir directory
Copy after login
If there are other files in the directory, you can use the rm -r command to delete Recursively delete all files in this directory. It should be noted that using this command will delete the directory and all data in the directory. The process is irreversible and needs to be used with caution:

rm -r directory
Copy after login

3、链接文件

linux中链接文件是指向一个真实存在的文件链接,是一种特殊文件,链接文件可以分为硬链接文件和符号链接文件两种。

链接文件一般指的是一个文件的软连接(或符号链接),使用 ls -l 命令查看,第一个符号为  "l",文件名为浅蓝色,如下:

这里,test_softlink 就是一个链接文件,从结果上还可以看到它是文件 test.txt 的软链接,删除原文件 test.txt 的话,对应的软链接文件 test_softlink 也会消失。可以使用 ln 命令来创建一个文件的链接文件:

1)软链接

  软链接(又称符号链接),使用 ln -s file file_softlink 命令可以创建一个文件的软链接文件:

ln -s test.txt test_softlink
Copy after login

  软链接相当于给原文件创建了一个快捷方式,如果删除原文件,则对应的软链接文件也会消失。

2)硬链接

  硬链接,相当于给原文件取了个别名,其实两者是同一个文件,删除二者中任何一个,另一个不会消失;对其中任何一个进行更改,另一个的内容也会随之改变,因为这两个本质上是同一个文件,只是名字不同。使用 ls -i 命令查看,可以发现硬链接的两个文件的 inode 号是一样的:

  同样的,使用 ln 命令可以创建一个文件的硬链接:

ln test.txt test_hardlink
Copy after login

4、设备文件

Linux 中的硬件设备如硬盘、鼠标等也都被表示为文件,即为设备文件。

linux中设备文件的作用是访问外部设备,是一种特殊文件,设备文件可以为外部设备提供标准接口。

设备文件一般存放在 /dev/ 目录下,文件名为黄色,如下:

设备文件分两种:

1)块设备文件:

  块设备文件支持以块(block)为单位的访问方式。在 EXT4 文件系统中,一个 block 通常为 4KB 的大小,也就是说每次可以存取 4096(或其整数倍) 个字节的数据。应用程序可以随机访问块设备文件的数据,程序可以自行确定数据的位置,硬盘、软盘等都是块设备。使用 ls -l 命令查看,块设备文件的第一个字符是 "b"(block)。

2)字符设备文件:

  字符设备文件以字节流的方式进行访问,由字符设备驱动程序来实现这种特性,这通常要用到 open、close、read、write 等系统调用。字符终端、串口和键盘等就是字符设备。另外,由于字符设备文件是以文件流的方式进行访问的,因此可以顺序读取,但通常不支持随机存取。使用 ls -l 命令查看,字符设备文件的第一个字符是 "c"(char)。

5、管道文件(FIFO文件)

linux中管道文件的作用是用于不同进程的信息传递,常用于两个进程的数据或信息传递,管道文件一般建立在调整缓存中。

使用 ls -l 命令查看,第一个字符为 "p"(pipe)。可以使用 mkfifo 命令来创建一个管道文件:

mkfifo fifo_file
Copy after login

在 FIFO 中可以很好地解决在无关进程间数据交换的要求,FIFO 的通信方式类似于在进程中使用文件来传输数据,只不过 FIFO 类型的文件同时具有管道的特性,在读取数据时,FIFO 管道中同时清除数据。 

相关推荐:《Linux视频教程

The above is the detailed content of What are the basic file types in Linux?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!