输出“ls -l”命令中有多少种可能的文件类型?

输出“ls -l”命令中有多少种可能的文件类型?

通常,输出命令中可能的文件类型ls -ld-,分别代表目录和常规文件。

除此之外,我l在 macOS 上的输出中看到了另一种类型。

drwxr-xr-x   8 yongjia  staff    256 Aug 31 06:58 .
drwxr-xr-x   4 yongjia  staff    128 Aug 30 11:31 ..
lrwxr-xr-x   1 root     wheel      1 Aug 17 07:25 Macintosh HD -> /

那么,输出ls -l命令中有多少种可能的文件类型?

答案1

报告的文件类型ls取决于底层文件系统、操作系统的功能以及ls.

类型l是常见的符号链接文件类型。

这(应该)记录在您的ls手册中。

在 OpenBSD 上(macOS 和 AIX 具有相同的列表,但顺序不同):

-     regular file
b     block special file
c     character special file
d     directory
l     symbolic link
p     FIFO
s     socket link

在 NetBSD 上(FreeBSD 也有相同的,不带aA):

-     Regular file.
a     Archive state 1.
A     Archive state 2.
b     Block special file.
c     Character special file.
d     Directory.
l     Symbolic link.
p     FIFO.
s     Socket link.
w     Whiteout.

来自info ls(即GNUls手册):

‘-’
     regular file
‘b’
     block special file
‘c’
     character special file
‘C’
     high performance (“contiguous data”) file
‘d’
     directory
‘D’
     door (Solaris 2.5 and up)
‘l’
     symbolic link
‘M’
     off-line (“migrated”) file (Cray DMF)
‘n’
     network special file (HP-UX)
‘p’
     FIFO (named pipe)
‘P’
     port (Solaris 10 and up)
‘s’
     socket
‘?’
     some other file type

在 Solaris 11 上:

d
The entry is a directory.

D
The entry is a door.

l
The entry is a symbolic link.

b
The entry is a block special file.

c
The entry is a character special file.

p
The entry is a FIFO (or “named pipe”) special file.

P
The entry is an event port.

s
The entry is an AF_UNIX address family socket.

-
The entry is an ordinary file.

答案2

您可以info通过执行以下操作在页面中找到该信息info coreutils 'ls invocation'。在我的系统上,它包含以下摘录:

 The file type is one of the following characters:

`-'
      regular file

`b'
      block special file

`c'
      character special file

`C'
      high performance ("contiguous data") file

`d'
      directory

`D'
      door (Solaris 2.5 and up)

`l'
      symbolic link

`M'
      off-line ("migrated") file (Cray DMF)

`n'
      network special file (HP-UX)

`p'
      FIFO (named pipe)

`P'
      port (Solaris 10 and up)

`s'
      socket

`?'
      some other file type

相关内容