fsutil 硬链接不起作用?

发布于 2024-07-17 09:27:57 字数 713 浏览 3 评论 0原文

我正在寻找一种在 Windows 下创建硬链接的方法,我发现了此页面: http://technet.microsoft.com/en-us/library/cc788097.aspx

为了尝试一下,我在 C: 驱动器的根目录下创建了一个文件 (1.txt),其中包含 100 行以下内容:

C:\1.txt (2.598 字节):

test test test test test

然后我打开命令提示符并键入:

fsutil hardlink create C:\2.txt C:\1.txt

成功,2.txt 已创建,但是当我查看它的大小时,它恰好有 2.598 字节,并且还注意到一些奇怪的行为(据我对硬链接的理解):

  1. 如果我删除 2.txt (硬链接文件),则 1.txt 不会被删除,反之亦然。
  2. 如果我删除 1.txt(原始文件)后打开 2.txt,内容仍然相同。

fsutil 硬链接创建命令与复制命令有何不同? 如何在 Windows 下创建真正的硬链接?

我使用的是 Windows XP SP 3,文件系统是 NTFS。

I was looking for a way to create hard links under Windows and I found this page: http://technet.microsoft.com/en-us/library/cc788097.aspx

To try it out, I created a file (1.txt) on the root of my C: drive with 100 lines of the following content:

C:\1.txt (2.598 bytes):

test test test test test

Then I open the command prompt and typed:

fsutil hardlink create C:\2.txt C:\1.txt

Success, 2.txt was created but when I go to see it's size it has exactly 2.598 bytes and also noticed some strange behaviours (as far as my understanding of hard links goes):

  1. If I delete 2.txt (the hard linked file) 1.txt is not deleted, and vice-versa.
  2. If I open 2.txt after I delete 1.txt (the original file) the content is still the same.

How does the fsutil hardlink create command differs from the copy command? And how can I create a true hard link under Windows?

I'm using Windows XP SP 3, and my file system is NTFS.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烟火散人牵绊 2024-07-24 09:27:57

这正是应该发生的行为。 您确定您了解硬链接的工作原理吗? 硬链接实际上只是文件系统中引用完全相同文件的多个条目。 如果您创建一个文件的硬链接并修改该文件的一个实例,则另一个文件将显示您的更改,因为它们都引用磁盘上的相同数据块。

当您删除硬链接之一时,实际上只是删除引用该文件的文件系统条目之一。 在您删除其所有硬链接(包括原始硬链接)之前,该文件不会被删除。 删除 1.txt 后,2.txt 仍然存在,并且引用原来存在的同一文件,只是现在只有一个文件系统条目引用该文件(即 2.txt)。 2.txt 就是该文件。

That's exactly the behavior that supposed to happen. Are you sure you understand how hard links work? Hard links are really just multiple entries in the file system that refer to the exact same file. If you create a hard link to a file and modify one of the instances of the file, the other file will show up with your changes because they both refer to the same blocks of data on disk.

When you delete one of the hard links, you're really just deleting one of the file system entries referring to that file. The file doesn't get deleted until you delete all of its hard links (including the original one). After you delete 1.txt, 2.txt still exists and refers to the same file that was originally there, only now there is only a single file system entry referring to that file (namely, 2.txt). 2.txt is that file.

眼眸 2024-07-24 09:27:57

fsutil硬链接是如何创建的
命令与复制命令有何不同?
我怎样才能创建一个真正的硬链接
在 Windows 下?

创建硬链接文件后,尝试编辑其中一个文件。 您会发现更改已反映在这两个文件中。

尝试创建一个非常大的文件(例如视频或磁盘映像)的硬链接。 请注意,磁盘上的可用空间没有更改(或者如果必须将附加元数据写入磁盘以反映新的目录条目,则更改不会超过几个字节)。

How does the fsutil hardlink create
command differs from the copy command?
And how can I create a true hard link
under Windows?

After creating the hardlinked file, try editing either. You will discover that the changes are reflected in both files.

Try creating a hard-link of a very large file (say a video or disk-image). Notice that the available space on the disk has not changed (or not changed by more than a few bytes, if additional metadata had to be written to disk to reflect the new dir entry).

猛虎独行 2024-07-24 09:27:57

这才是真正的硬链接。 在 UNIX(我不熟悉 Windows 变体)中,文件只是磁盘上的一组数据(简单地说)。 目录条目本身为该文件提供了名称。

当您有两个目录条目指向同一个基础文件时,删除其中一个并不会删除该文件,除非它是附加到该文件的最后一个目录条目(并且该文件尚未由进程打开,但那是另一回事)。

That is a true hard link. In UNIX (I'm not familiar with the Windows variant) a file is just a set of data on the disk (simplistically). It's the directory entry itself that gives that file a name.

When you have two directory entries pointing at the same underlying file, deleting one of them does not delete the file unless it's the last directory entry attached to it (and the file is not still open by a process, but that's a different matter).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文