Can the same file have two different names?
Surprisingly the answer may well be yes. And it’s not just
different names but potentially different names in different
directories that can actually refer to the same file.
Unix and related operating systems have have been able to do this
for decades. What most people don’t realize is that Windows NT and its
successors Windows 2000 and Windows XP also support this; or rather
the NTFS filesystem supports this. “This” is the concept of “hard
links”. To understand what hard links are, we need to take a look at
what it means to be a directory entry for a file on disk.
Become a Patron of Ask Leo! and go ad-free!
When you open up Windows Explorer to view the contents of a folder
or do a “DIR” in a Command shell, you’re looking a a list of the files
in that folder or a “directory” of those files. The contents of each file live somewhere else on the hard disk; but the file’s name, date, and other information is stored in its directory entry.
Perhaps the most important bit of information stored in the
directory listing for a file the is location of its contents on the hard
disk. The operating system uses the directory information to actually
retrieve the contents when you read or modify it.
A common term is that the directory entry “points to” or “links to” the file as
illustrated by the diagram below:
So if each file’s contents is out on the hard disk and a directory
entry merely points to it then what prevents a second directory entry
from pointing to the same file contents?
In a word: nothing. At least not under NTFS. You can have many
directory entries pointing to the same file contents much
like this diagram:
If you change the contents of the file using any of the directory
entries that point to it then all of the directory entries will reflect the
Creating additional directory entries to point to a file is easy under
Windows XP though the command line is a bit long. You start by creating the file
however you normally would – that will create the single directory entry
and the file contents as illustrated in the first diagram above. To create
an additional directory entry that links to the same file in a Command
fsutil hardlink create newname existingfilename
“existingfilename” is the name of the file that already exists on disk. “newname”
is the filename to be used in the additional directory entry to be created. So
for example, if I have “c:\my documents\latest paper.doc” and I want that same file
to also appear elsewhere then I might enter:
fsutil hardlink create “c:\shared files\paper.doc” “c:\my documents\latest paper.doc”
“c:\my documents\latest paper.doc” and “c:\shared files\paper.doc”
are now two names for the same file. Change one and it shows up in the
Delete one and the other remains. Deleting a directory entry
only removes the directory entry. It’s only when the last directory
entry referencing a file is removed that the file itself is finally removed from the
One last limitation: hard links only work on the same drive. So for example you can’t have
linked directory entries on D: for files on C:.