


What are the basic file types in Linux?
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.
#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
Delete one Ordinary file:
You can use the rm command to delete a file:rm newfile
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
Delete one Directory:
You can use the rmdir command to delete an empty directory:rmdir directory
rm -r directory
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
软链接相当于给原文件创建了一个快捷方式,如果删除原文件,则对应的软链接文件也会消失。
2)硬链接
硬链接,相当于给原文件取了个别名,其实两者是同一个文件,删除二者中任何一个,另一个不会消失;对其中任何一个进行更改,另一个的内容也会随之改变,因为这两个本质上是同一个文件,只是名字不同。使用 ls -i 命令查看,可以发现硬链接的两个文件的 inode 号是一样的:
同样的,使用 ln 命令可以创建一个文件的硬链接:
ln test.txt test_hardlink
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
在 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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use Docker Desktop? Docker Desktop is a tool for running Docker containers on local machines. The steps to use include: 1. Install Docker Desktop; 2. Start Docker Desktop; 3. Create Docker image (using Dockerfile); 4. Build Docker image (using docker build); 5. Run Docker container (using docker run).

The key differences between CentOS and Ubuntu are: origin (CentOS originates from Red Hat, for enterprises; Ubuntu originates from Debian, for individuals), package management (CentOS uses yum, focusing on stability; Ubuntu uses apt, for high update frequency), support cycle (CentOS provides 10 years of support, Ubuntu provides 5 years of LTS support), community support (CentOS focuses on stability, Ubuntu provides a wide range of tutorials and documents), uses (CentOS is biased towards servers, Ubuntu is suitable for servers and desktops), other differences include installation simplicity (CentOS is thin)

Troubleshooting steps for failed Docker image build: Check Dockerfile syntax and dependency version. Check if the build context contains the required source code and dependencies. View the build log for error details. Use the --target option to build a hierarchical phase to identify failure points. Make sure to use the latest version of Docker engine. Build the image with --t [image-name]:debug mode to debug the problem. Check disk space and make sure it is sufficient. Disable SELinux to prevent interference with the build process. Ask community platforms for help, provide Dockerfiles and build log descriptions for more specific suggestions.

Docker process viewing method: 1. Docker CLI command: docker ps; 2. Systemd CLI command: systemctl status docker; 3. Docker Compose CLI command: docker-compose ps; 4. Process Explorer (Windows); 5. /proc directory (Linux).

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

Docker uses Linux kernel features to provide an efficient and isolated application running environment. Its working principle is as follows: 1. The mirror is used as a read-only template, which contains everything you need to run the application; 2. The Union File System (UnionFS) stacks multiple file systems, only storing the differences, saving space and speeding up; 3. The daemon manages the mirrors and containers, and the client uses them for interaction; 4. Namespaces and cgroups implement container isolation and resource limitations; 5. Multiple network modes support container interconnection. Only by understanding these core concepts can you better utilize Docker.

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.
