Sunday, May 16, 2004 1:33 AM bart

Symbolic links on NTFS

Symbolic links are a way to create an "alias" for a file. This is not the same as a shortcut in Windows but rather is a "pointer" to a file or directory with another name. In fact, quite a lot of people think that this is a UNIX-only feature. However, this is available for NTFS as well (okay, I have to admit - it's living in the Services For Unix package :-)). Actually, there's more. We're not happy to tell you should use Servcies For Unix to do this, so in Windows Server 2003 you can do it using the fsutil tool as well. Let me explain:

C:\Documents and Settings\Administrator>fsutil hardlink create test.cpy test.txt

Hardlink created for C:\Documents and Settings\Administrator\test.cpy <<===>> C:\Documents and Settings\Administrator\test.txt

By doing this, you can access the test.txt file using test.cpy now as well. You'll find the file if you're performing a dir command, just as you expect. When you modify something in the test.txt or test.cpy file it will be visible on the test.cpy and test.txt files respectively (since it's physically the same file of course). The use of erase on file.cpy will not delete the test.txt file itself, but only the link to the file. When you delete the test.txt file using erase, the file won't be deleted since a link to the file still exist (his is important to know!).

When you're using the ln.exe tool, it works almost the same. The only thing you should take care of is the use of the correct parameters. For a file link, you should use ln.exe -f <original file> <alias>. If you're using ln.exe -fs, the result is pretty cool (or is it a bug?):

C:\Documents and Settings\Administrator>type test.txt
Hello
C:\Documents and Settings\Administrator>ln -fs test.txt test.cpy

C:\Documents and Settings\Administrator>type test.cpy
IntxLNK?t e s t . t x t

As you can see, the fle contains a link. But when you open the file using Notepad, the tool doesn't see this quite well:

????test.txt

The ln.exe -f in contrast works well:

C:\Documents and Settings\Administrator>ln -f test.txt test.cpy

C:\Documents and Settings\Administrator>type test.cpy
Hello

I guess I'm experimenting a bit too much :-)

Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks

Filed under:

Comments

# re: Symbolic links on NTFS

Tuesday, June 08, 2004 7:45 PM by bart

These are hard links, not symbolic links!

# re: Symbolic links on NTFS

Wednesday, September 15, 2004 1:51 PM by bart

shouldn't the result of
type text.cpy be Hello for true symbolic linking ?

# re: Symbolic links on NTFS

Wednesday, September 15, 2004 1:52 PM by bart

oops sorry, didn't read far enough :)

# re: Symbolic links on NTFS

Wednesday, September 15, 2004 2:25 PM by bart

but (as already stated) this is not a symbolic link at all!
try to do this:
echo joker>joker.txt
fsutil hardlink create hoho.txt joker.txt
del joker.txt

type hoho.txt still works..
wheras in unix a file not found alike message would occur..

# re: Symbolic links on NTFS

Wednesday, March 09, 2005 11:43 AM by bart

I've found another solution, if you follow the URL.

Also, you could create a batch file, and drop it (or a short cut/link to it) in the SendTo directory. Here's the contents of my batch file:

fsutil hardlink create %1.link %1

# re: Symbolic links on NTFS

Wednesday, March 23, 2005 11:28 AM by bart

My Friend:

you shouldn't experiment too much but read the documentation instead.

And you schould read about symbolic links and hard links.

Afterwards read what you worte again and you will feel a hot feeling in your face. If you feel that, then I predict, your face will be red when you look into the mirror...

(Just joking)...