Page 1 of 1

Symlink in Linux and Windows

Posted: 05 Mar 2013, 11:59
by viking60
Most Linux users know how to use symlinks and the others can have a look here.
In Linux: If I want to symlink my server from /var/www/html to ~/public_html I go to ~/ and enter:

Code: Select all

ln -s /var/www/html public_html

This will create the public_html symlink in my home directory and I can work with my files there.

It makes life easier If we want our music accessible from our Desktop in stead of from /home/user/Documents/Music/rock/black_metal/heluva_music

It will be accessible from the desktop even if the actual data are kept in /home/user/Documents/Music/rock/black_metal/heluva_music
So symlinks are basically advanced shortcuts which make important files accessible from multiple locations

But not everybody knows that you can symlink in Windows too.
For that you need to install the free Link Shell Extension On this page you will also find Visual Studio 2005 redistributable whis is neccessary to set things up so download and install both.

(Who said that Windows was easier than Linux? :confused :-D )

So now we are ready to go then:
Windows 7/Vista
You need to open an administrator command prompt (cmd).
Image

Now we have the cmd "terminal" open and can writer the command with the following syntax:

Code: Select all

mklink /prefix link_path file/folder_path

(Notice that this is opposite of the Linux syntax where the actual content comes first and the symlink location second.)
mklink can be used in combination with the following switches:
/D – creates a soft symbolic link, which is similar to a standard folder or file shortcut in Windows. This is the default option, and mklink will use it if you do not enter a prefix.
/H – creates a hard link to a file
/J – creates a hard link to a directory or folder

So if I want the content of my dropbox accesible from my desktop instead of from Documents I would do something like this

Code: Select all

mklink /J C:\Users\viking\Desktop\Dropbox C:\Users\viking\Documents\Dropbox

Again: C:\Users\viking\Desktop\Dropbox is where I want it to appear and C:\Users\viking\Documents\Dropbox is where the data are.

So if you navigate to your desktop in explorer you will find all the dropbox data there.

This was for directories but you can use the same syntax for a file.

If there are spaces in your paths you have to put quotes(") around it - like this:

Code: Select all

mklink /H “C:\Users\viking\Desktop\RTFM.pdf”  “C:\Users\viking\Downloads\Before you ask for support.pdf”


In windows XP this will not work you will have to use something called junction instead (it is a free tool).
go to the path (cd) were you saved junction and enter your commands there.

Code: Select all

junction –s link_path file/folder_path

junction can only create hard symlinks.
To create a symlink to the music folder on the desktop:

Code: Select all

junction -s “C:\Documents and Settings\Administrator\Desktop\Music” “C:\Documents and Settings\Administrator\My Documents\My Music”


Well that is about it - and it is a bit complicated. And it works differently on different Windows versions - not so in Linux

When will those Windows guys stop fiddling :boohoo: with the complicated command prompt - with those complicated commands - and just make things work out of the box? :mrgreen:

Re: Symlink in Linux and Windows

Posted: 04 Nov 2013, 11:20
by viking60
Wiki added.

Re: Symlink in Linux and Windows

Posted: 04 Nov 2013, 14:47
by dedanna1029
Nice!