windows - mklink /j vs mklink /d on multiple machines and with file shares
2014-07
I'm starting to use cloud sharing solutions (e.g., Dropbox, SpiderOak) to backup and sync files between various machines I use. When doing this I've decided to place all my backups under a given directory (some solutions require this).
But I want to keep my current folder structure, so as an example, if I had
Stuff1
I'll now have
Stuff1 ==> D:\path\to\SpiderOak\Stuff1
or
Stuff1 ==> D:\path\to\Dropbox\Stuff1
This solution allows me to continue to work with the directory paths I've been using and get files backed up to the cloud as well.
I've experimented with mklink, mklink /d, and mklink /j and come to the conclusion that only mklink /j has any value. Here's why I say this. On FileServer1 I have:
cd /d r:\h\user1
dir
... output below ...
<JUNCTION> Stuff1-JUNCTION-FS1 [r:\H\user1\SpiderOak\Stuff1]
<SYMLINK> Stuff1-SYMLINK-FS1 [SpiderOak\Stuff1]
<SYMLINKD> Stuff1-SYMLINKD-FS1 [SpiderOak\Stuff1]
NOTE1: These were created with mklink /j (for junction), mklink /d (for SYMLINKD), and mklink with no args (for SYMLINK).
On VM1, I have h: mounted as \\FileServer1\h (i.e., net use h: \\FileServer1\h)
cd /d h:\user1
dir
... output below ...
<JUNCTION> Stuff1-JUNCTION-FS1 [r:\H\user1\SpiderOak\Stuff1]
<SYMLINK> Stuff1-SYMLINK-FS1 [SpiderOak\Stuff1]
<SYMLINKD> Stuff1-SYMLINKD-FS1 [SpiderOak\Stuff1]
<SYMLINKD> Stuff1-SYMLINKD-VM1 [SpiderOak\Stuff1]
Now my questions:
(Q) Is there any way to know that I'm using a junction? What is the Windows equivalent for the UNIX pwd -P (see http://linux.die.net/man/1/pwd)? For example,
cd h:\user1\Stuff1
pwd -P
... output would be ... R:\h\user1\SpiderOak1\Stuff1
(Q) On VM1, why doesn't the SYMLINKD link work? From what I've read it only works on local systems, but why doesn't the "Stuff1-SYMLINKD-VM1" work when I'm on that VM1?
dir Stuff1-JUNCTION-FS1 ==> WORKS
dir Stuff1-SYMLINKD-FS1 ==> says the file doesn't exist
dir Stuff1-SYMLINKD-VM1 ==> says the file doesn't exist
(Q) Is there any reason I would want to use mklink /d, it appears that mklink /j is more suited to the general solution and there is no benefit to ever using mklink /d. Am I missing something that mklink /d can do that mklink /j can't?
(Q) Is there any way to create a junction that uses a "relative path"? For example, the following commands still create an absolute path.
ON FileServer1:
cd /d r:/h/user1
mklink /j foo bar
dir
... output ...
<JUNCTION> foo [r:\H\user1\bar]
On Unix, you can create symlinks to relative paths or absolute paths, it can matter (on UNIX).
(Q) Is there any way to create a link that points to a local filesystem copy of data? For example, h:\user1\LocalStuff ==> C:\LocalStuff
When I'm on FileServer1's copy of LocalStuff is used, but when I'm on another computer the local data is used:
FileServer1:C:\LocalStuff
VM1:C:\LocalStuff
VM2:C:\LocalStuff
Just FYI... I've had good results with Dropbox and I "trust Dropbox" to work as I expect. I've run into some issues with SpiderOak and believe they were caused by my use of symlink's. I contacted SpiderOak tech support and they said, yeah... don't do that (don't use symlinks). This was causing duplicate copies of data being made and strange behavior that I never did understand. I eventually created a new account, started over and have had much better results.
This Microsoft documentation lacks any mention of the limitations of symlinks:
http://technet.microsoft.com/en-us/library/cc753194.aspx.
(Q) If there is a better link, please share it with me.
The following links were helpful (there are several good ones):
http://www.sevenforums.com/tutorials/278262-mklink-create-use-links-windows.html,
http://www.rekenwonder.com/linkmagic.htm,
http://schinagl.priv.at/nt/hardlinkshellext/hardlinkshellext.html
Best regards.
If I've created a directory link via mklink, how can I figure out if it was a symbolic link, a directory junction, or a hard link (ie whether I used /d, /j, or /h)?
At the command line you can type
dir /a
You should see something similar to:
02/08/2010 11:40 PM <SYMLINKD> d1 [..\targetdir1]
02/08/2010 11:41 PM <JUNCTION> d2 [..\targetdir2]
This shows a directory symlink (/D
) and a directory junction (/J
)