Does Windows have the ln -s or equivalent?

38

14

I need to link a file to C:\Windows\System32\drivers\etc\hosts

How can I do that with Windows ? Is there a soft link such as ln -s or equivalent in Windows ?

prosseek

Posted 2010-08-30T15:39:12.460

Reputation: 4 635

Answers

39

You are looking for the command "mklink".

Documentation and examples in Microsoft Docs or ss64.com.

Example taken from the link:

// To create a symbolic link named MyDocs from the root directory to the \Users\User1\Documents directory, type:
mklink /d \MyDocs \Users\User1\Documents

scigor

Posted 2010-08-30T15:39:12.460

Reputation: 913

4Please note that you need Administrator privileges to create symbolic links. – Andres Riofrio – 2012-07-26T21:46:50.233

16

There may be other ways, but the one I'm familiar with is mklink:

C:\>mklink 
Creates a symbolic link.

MKLINK [[/D] | [/H] | [/J]] Link Target

        /D      Creates a directory symbolic link.  Default is a file
                symbolic link.
        /H      Creates a hard link instead of a symbolic link.
        /J      Creates a Directory Junction.
        Link    specifies the new symbolic link name.
        Target  specifies the path (relative or absolute) that the new link
                refers to.

Matthew S

Posted 2010-08-30T15:39:12.460

Reputation: 261

3

There are junctions but I don't know if this will do exactly what you need.

edit - oops sorry, junction only applies to directories not files

Martin Beckett

Posted 2010-08-30T15:39:12.460

Reputation: 6 073

2

Link Shell Extension can create symbolic link (among other things). Nice context menu integration. Available for the most recents windows versions and frenquently updated.

Francois

Posted 2010-08-30T15:39:12.460

Reputation: 21

2

As @inf says, mklink is the solution for Vista and above.

For 2000/XP, you can use fsutil hardlink. Note that, unlike mklink, hardlink doesn't work across drives.

studgeek

Posted 2010-08-30T15:39:12.460

Reputation: 1 805

According to the link you provided, fsutil hardlink, fsutil hardlink is only for Vista and above. Is there an older version available for Windows 2000 and XP?

– matty – 2015-07-08T05:34:18.257

Indeed it is available for XP, as described in the Windows XP fsutil hardlink docs. I can't testify to its functionality in Windows 2000, but it does work in Windows XP.

– matty – 2015-07-08T07:53:23.143

1Also worthy of note is that some people may not be aware, but hardlinks become the file. In other words it's possible to delete the original and the link still works (and this is why it can't work across drives). – Camilo Martin – 2013-09-09T02:05:05.537

1

Powershell

As long as Microsoft advices to use as a command interpreter since more than 5 years ago and cmd.exe is becoming a legacy application this question lacks an answer in Powershell:

New-Item -path ~\Desktop\hosts -itemType SymbolicLink -target c:\Windows\System32\Drivers\etc\hosts

This works as of Powershell v5.0

maoizm

Posted 2010-08-30T15:39:12.460

Reputation: 739

-2

open the Terminal/CMD under the android/sdk/tools,type

Terminal** ln -s emulator64-x86 emulator-x86** CMDmklink emulator64-x86 emulator-x86

this will get created like..

symbolic link created for emulator64-x86 <<===>> emulator-x86

INTRA TUBE

Posted 2010-08-30T15:39:12.460

Reputation: 1