Linux文件类型

Linux文件类型

For normal files in the file system, Unix does not impose or provide any internal file structure. This implies that from the point of view of the operating system, there is only one file type.

The structure and interpretation thereof is entirely dependent on how the file is interpreted by software.

Unix does however have some special files. These special files can be identified by the ls -l command which displays the type of the file in the first alphabetic letter of the file system permissions field.

在操作系统角度,Unix系统只有一种文件类型。这里研究的文件类型只是表明文件室如何被软件解释执行的。

不过Unix系统确实存在一些特殊的文件。使用 ls -l 命令显示的文件系统的权限字段的第一个字符,可以识别这些文件的类型。

  • - : Regular file,普通文件
  • d : Directory,目录
  • l : Symbolic link,符号连接文件
  • p : Named pipe,命名管道文件
  • s : Socket,套接字文件
  • c/b : Device file,设备文件
  • D : Door

Regular file

Being the well known entity that files are, files are also called “regular files” to distinguish them from “special files”.

They show up in ls -l without a specific character in the mode field

-rwxr-xr-x 26 root root 4096 Sep 22 09:29 temp.txt

普通文件,依照文件的内容,又大致可以分为:
+ 纯文本文件
+ 二进制文件
+ 数据格式的文件


Directory

A directory is marked with a d as the first letter in the mode field in the output of ls -l.

drwxr-xr-x 26 root root 4096 Sep 22 09:29 Music

A symbolic link is a reference to another file.

A symbolic link is marked with an l (lower case L) as the first letter of the mode string.

lrwxrwxrwx 1 root root  33 04-19 11:27 kernel.rpm -> kernel-2.6.15-1.2025_FC5.i686.rpm 

符号连接文件,类似Windows下的快捷方式。


Named pipe

In computing, a named pipe (also known as a FIFO for its behavior) is an extension to the traditional pipe concept on Unix and Unix-like systems, and is one of the methods of inter-process communication (IPC).

A named pipe is marked with a p as the first letter of the mode string

prw-rw---- ... mypipe

命名管道文件(FIFO):是一种特殊的文件类型,作为数据管道方便程序之间的通信,管道实际缓存了来自第一个进程的输入数据。

它主要的目的是解决多个程序同时存取一个文件所造成的错误。

FIFO,是first-in-first-out(先进先出)的缩写。


Socket

A socket is a special file used for inter-process communication. These allow communication between two processes.

A socket is marked with an s as the first letter of the mode string

[root@localhost ~]# ls -lh /var/lib/mysql/mysql.sock  
srwxrwxrwx 1 mysql mysql 0 04-19 11:12 /var/lib/mysql/mysql.sock 

套接字文件是方便进程之间通信的特殊文件,通常用于网络数据连接。与管道不同的是,套接字能促使通过网络连接的不同计算机的进程之间进行通信。套接字文件也不与任何数据块关联。


Device file

In Unix, almost all things are handled as files and have a location in the file system—even hardware devices.

Device files are used to apply access rights and to direct operations on the files to the appropriate device drivers.

Unix makes a distinction between character devices and block devices. The distinction is roughly as follows:
+ character devices provide only a serial stream of input or output;
+ block devices are randomly accessible;

A character device is marked with a c as the first letter of the mode string. Likewise, a block device is marked with a b.

[root@localhost ~]# ls -al /dev/tty
crw-rw-rw- 1 root tty 5, 0 11-03 15:11 /dev/tty
[root@localhost ~]# ls -la /dev/sda1
brw-r----- 1 root disk 8, 1 11-03 07:11 /dev/sda1

字符设备文件:串行端口的接口设备,如鼠标、键盘、猫等。
块设备文件: 存储数据以供系统存取的接口设备,如硬盘、光驱等。


Door

A door is a special file for inter-process communication between a client and server, currently implemented only in Solaris.

A door is marked with a D (upper case) as the first letter of the mode string

Dr--r--r-- ... name_service_door
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值