2

Coming from a unix-based environment, I expected to be able to create symbolic links in a Windows 7 command prompt using mklink or a similar function. Indeed, I find that I can do this, but if the link already exists, I find I cannot overwrite the link with a 'force' option, as you can in unix with ln -sf.

Is there a way that I can create a symbolic link with the same name and overwrite any existing link, all in one command? I'm surprised that the list of options here doesn't allow this, from what I've seen.

noisebelt
  • 940
  • 2
  • 9
  • 20
  • Why does it need to be one command? – Harry Johnston Jan 06 '14 at 20:48
  • I work in a development group with multiple configurations for our application. As a result, whenever we want to reconfigure the application we repoint the symbolic link to the appropriate configuration file. In linux, you can easily overwrite an existing symbolic link with a new one by adding the -f flag, but in Windows, apparently you can't. – noisebelt Jan 07 '14 at 19:25
  • In Windows, you can easily overwrite an existing symbolic link by deleting it and then creating the new one. The only difference is it takes two commands rather than one to do it. I'm asking why the extra command matters to you. – Harry Johnston Jan 07 '14 at 20:49
  • I like thinks to be concise. – noisebelt Jan 08 '14 at 21:43
  • You'll need to use a third-party solution, then, or write your own. – Harry Johnston Jan 09 '14 at 03:12
  • @HarryJohnston it's called atomicity. – reformed Apr 06 '23 at 21:01

1 Answers1

1

You can use PowerShell to overwrite an existing symlink using the -Force argument:

New-Item -ItemType SymbolicLink -Path "/existing/symlink/path" -target "/new/target/path" -Force

reformed
  • 4,505
  • 11
  • 62
  • 88