Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 338 down vote accepted

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.

share|improve this answer
Having just accidentally done this (deleted the complete contents of the target folder), this an important tip. – Simon Gillbee Aug 8 '11 at 21:10
F**k! Me too... God bless backups... We should upvote this to "outvote" the accepted answer :) – jitbit Mar 15 '12 at 10:56
This answer is not entirely accurate. Del deletes files, not folders. Therefore, you would not use del to delete the link. – AMissico Mar 12 '13 at 1:47
But don't use rmdir in PowerShell. Wrap it in cmd first. See my answer below... – northben May 13 '13 at 21:25
How about if i delete it through windows explorer???? – Cheung Tat Ming Aug 11 '13 at 16:49

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

share|improve this answer
Warning: "del" will delete the file and not just the link. – WoodenKitty Nov 12 '15 at 0:39
Warning from @Tristan is not correct, this answer is accurate. Tested on windows 7. – jiggunjer Jun 23 at 3:07

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

share|improve this answer
+1 for telling people it is save to delete symbolic link through Windows Explorer. – AMissico Mar 12 '13 at 1:45

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


share|improve this answer
Just make sure you don't delete it with del /S or Explorer. – Hello71 Jul 24 '10 at 0:12
See eddyq's answer below because using del for a link made to a directory won't work and instead will attempt to delete teh contents of the folder. – jpierson May 7 '12 at 13:48
Hardlinks to directories don't exist. I think you meant to say symlink. – Brilliand Sep 8 '15 at 18:20

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

share|improve this answer
That blog confuses the meaning of "Target", which is the actual directory the link points to, and which folks generally wish to avoid deleting whilst removing the link. – kreemoweet Sep 22 '15 at 16:59

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.

share|improve this answer
yeah, this is 100% safest solution after you know that powershell does not give a s**t about rmdir – test30 Jul 3 '14 at 14:54
This is a clever precaution. +1 – Johannes Mar 4 '15 at 17:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .