mklink: How do you make a symbolic link to a file in command prompt when the file aready exists?

2.7k views Asked by At

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.

1

There are 1 answers

1
reformed On

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