437

I created a symlink using mklink. Now I need to change it but I can't figure out how to delete it so I can recreate it correctly.

Ben V
  • 4,542

13 Answers13

735

Be very careful.

If you have a symbolic link that is a directory (made with mklink /d) then using del will delete all of the files in the target directory (the directory that the link points to), rather than just the link.

SOLUTION: rmdir on the other hand will only delete the directory link, not what the link points to.

eddyq
  • 7,384
129

To remove directory symbolic links created with mklink /d it is safe to delete the symbolic link in windows explorer.

ddelrio1986
  • 1,399
59

For a symlink to a file, use del. For a symlink to a directory made with mklink /d, use rmdir.

34

In Powershell, don't use rmdir! Use cmd /c rmdir .\Target instead. I tested this myself and confirmed it here.

northben
  • 1,171
28

There is another solution tested by me and safe to use. just add to the real folder _ (example: foo become foo_) then simply delete your symbolik link, then remove _ from your true folder.

vcorp
  • 389
24

mklink cannot be used to delete symbolic links. To remove a symbolic link, simply delete them as if you’re removing a normal file. For example, to delete the foo symbolic link created above, enter the following command:

If the link is a hard link to a directory:

C:\test>rmdir foo

or else, IF the link points to a file (as opposed to a dir)

C:\test>del foo

Source: Create Symbolic Links, Hard Links and Directory Junctions in Vista with MKLINK

Daisetsu
  • 6,171
3

I've installed this Link Shell Extension. With this, you have 2 methods.

METHOD 1

Create it using the context menu as shown and deleting via file explorer.

Test with a folder like C:\Windows\Logs as shown or similar. I'm just creating a directory of all the possible locations of temp files to delete and I wanted a central folder where I could monitor the size of them via symbolic links.

Please note: The screen going white is just the UAC.

delete from explorer method

METHOD 2

The safest way undocumented here AFAIK.

On the created symbolic link (in steps shown above), right-click on it this time and click properties then go to the Link Properties tab.

Note: This shell extension added this tab.

Before I go on, lots more info can be found here, also, on the homepage are the x64 and 32bit versions.

So, to continue, here you can add anything to the target field as long as it's different to the original target.


  1. Here's a before with the target as C:\Windows\Logs target before

  2. Here's an after with the target as C:\Windows\Logs_, notice the extra _ at the end.

    target after

  3. Press OK

  4. You can check this again by going over the same 1-3 steps above to ensure that has stuck, this time you will get an error message when you click on the Link Properties tab so the link is now broken.

  5. It is now safe(r) to delete the symbolic link than method 1 IMHO.


But! Both methods work here so it's entirely up to the user's choice. I like the properties method which I happily stumbled upon, so you're 100% sure the link is broken by using step 4 above.

Here's a gif of me creating a symbolic link by right mouse button dragging a folder to another and choosing the option to create a symbolic link in the sub-menu.

To delete, just follow the 1-5 steps above of method 2 or follow method 1.

How to create and delete a symbolic link using the properties method

Please note: The screen going white is just the UAC.

gif on how to create and delete syn links using the properties method

Ste
  • 1,352
1

In my case (Windows 10), after creating the symbolic link using

MKLINK /D "C:\Users\username\Dropbox\MyProject" "C:\SourceProject"

and deleting via delete using the file explorer or keyboard delete key also deletes the original directory.

What you should do is to remove the link via command prompt using rd command.

C:\Users\username\Dropbox>rd /s MyProject
tetedp
  • 111
1

The simplest way is to move the folder (at which the symbolic link is pointing) to another place (to parent folder) and then delete the symbolic link. No files will be harmed!

netgoblin
  • 111
1

Create Windows 10 directory symbolic link:

MKLINK /D "C:\Users\andronoid\Program Files" C:\Users\andronoid\AppData\Local

Delete Windows 10 directory symbolic link:

andronoid
  • 153
1

There is one odd case not handled by any of the excellent answers here. That is when someone creates a file symbolic link to a folder (directory). This typically happens when someone has made a little boo-boo and forgot to include the "/D" option with mklink.

Not that I have ever done that. No, never. ;)

In this rare case, using the del command will successfully remove the symlink. And more sleep will help prevent this rare breed of symlink in the first place.

0

I've deleted the symbolic link folder on my server.

1)I've deleted the sub files and folders in the symbolic link.

Get-ChildItem D:\test\link\ -Recurse | Remove-Item -Force -Recurse*

2)I've deleted the target folders.(this command similuare with chttps://superuser.com/a/684697/1749990).

Get-ChildItem "D:\test\link" | Get-Item | Select-Object -ExpandProperty Target | Remove-Item -Force -Recurse

3)Finally, I've deleted the link folders successfully.

cmd /c rmdir (Get-ChildItem -Path "D:\test\link" | Select-Object -ExpandProperty FullName)

jaegun
  • 1
  • 1
0

I managed to delete executable links that vim put on my windows machine Desktop, pressing windows, finding Terminal, right clicking the app and choosing Run as Administrator

Then, using Powershell, you navigate to the location, here are some helpful locations:

C:\Users\Public\Desktop

C:\ProgramData\Microsoft\Windows\Start Menu\Programs[PROGRAM FOLDER]

Then when you find the shortcuts:

rm desiredfile.lnk