0

我知道这真的很基础,但是我在 ls 手册页中找不到这些信息,需要复习一下:

$ ls -ld my.dir
drwxr-xr-x    1 smith users      4096 Oct 29  2011 my.dir

drwxr-xr-x 后面的数字 1 是什么意思?它是否代表目录 my.dir 的硬链接数?我不记得。我在哪里可以找到这些信息?

谢谢,

约翰·戈切

4

3 回答 3

3

我在维基百科上找到了它:

duuugggooo (hard link count) owner group size modification_date name

该数字是硬链接计数。

如果您想要更 UNIXy 的解决方案,请键入info ls. 这提供了更详细的信息,包括:

`-l'
`--format=long'
`--format=verbose'
     In addition to the name of each file, print the file type, file
     mode bits, number of hard links, owner name, group name, size, and
     timestamp (*note Formatting file timestamps::), normally the
     modification time.  Print question marks for information that
     cannot be determined.
于 2012-07-15T08:23:16.433 回答
3

那是文件的命名(硬链接)数。我想,这里有一个错误。对于目录,此处必须至少为 2。

$ touch file
$ ls -l
total 0
-rw-r--r-- 1 igor igor 0 Jul 15 10:24 file
$ ln file file-link
$ ls -l
total 0
-rw-r--r-- 2 igor igor 0 Jul 15 10:24 file
-rw-r--r-- 2 igor igor 0 Jul 15 10:24 file-link
$ mkdir a
$ ls -l
total 0
drwxr-xr-x 2 igor igor 40 Jul 15 10:24 a
-rw-r--r-- 2 igor igor  0 Jul 15 10:24 file
-rw-r--r-- 2 igor igor  0 Jul 15 10:24 file-link

正如你所看到的,一旦你创建了一个目录,你就会在列中得到 2。

当您在目录中创建子目录时,数量会增加:

$ mkdir a/b
$ ls -ld a
drwxr-xr-x 3 igor igor 60 Jul 15 10:41 a

如您所见,该目录现在具有三个名称(其中包含“a”、“.”和其子目录中的“..”):

$ ls -id a ; cd a; ls -id .; ls -id b/..
39754633 a
39754633 .
39754633 b/..

所有这三个名称都指向同一个目录 ( inode 39754633)。

于 2012-07-15T08:24:02.287 回答
0

试图解释为什么目录的初始链接计数值=2。PL。看看这是否有帮助。

任何文件/目录都由 inode 标识。硬链接数 = 对 inode 的引用数。

创建目录/文件时,会在父目录中创建一个目录条目(形式为 - {myname, myinodenumber})。这使得该文件/目录的 inode 的引用计数 = 1。

现在,当除此之外创建目录时,还会创建目录空间,默认情况下应该有两个目录条目,一个用于创建的目录,另一个用于父目录,它是 {., myinodenumber} 形式的两个条目和 {.., myparent'sinodenumber}。

当前目录由“.”引用 父母由 ".." 引用。

因此,当我们创建目录时,Links 值的初始数量 = 1+1=2,因为有两个对 myinodenumber 的引用。并且父级的链接值数量增加 1。

于 2012-07-15T14:50:16.727 回答