Symlink in Linux and Windows

Every day solutions to every day challenges. + Brilliant stuff

Moderators: b1o, jkerr82508

Forum rules
Please feel free to post your tip it does not have to be advanced. Also ask questions directly related to the tip here. But do not start new threads with questions or ask for help here. That is what the help section is for. forum rules: http://bjoernvold.com/forum/viewtopic.php?f=8&t=568
User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Symlink in Linux and Windows

Postby viking60 » 05 Mar 2013, 11:59

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:
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Symlink in Linux and Windows

Postby viking60 » 04 Nov 2013, 11:20

Wiki added.
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
dedanna1029
Sound-Berserk
Posts: 8784
Joined: 14 Mar 2010, 20:29
Contact:

Re: Symlink in Linux and Windows

Postby dedanna1029 » 04 Nov 2013, 14:47

Nice!
I'd rather be a free person who fears terrorists, than be a "safe" person who fears the government.
No gods, no masters.
"A druid is by nature anarchistic, that is, submits to no one."
http://uk.druidcollege.org/faqs.html


Return to “Tips & Tricks”