How to Delete a Junction by Using Command Prompt in Windows 7

104

20

I believe in Windows Vista, we could use linkd command. However, I cannot find this command in Windows 7. I know I can use Windows Explorer and delete the junction, but I wonder if this can be done in Command Prompt.

I can use mklink command to create a junction from a Command Prompt, so, what is the opposite of it (something like linkd)?

Nord

Posted 2011-05-19T04:14:35.850

Reputation: 1 165

Answers

136

Delete junctions with rmdir (rd). Works in all Windows versions.

user1686

Posted 2011-05-19T04:14:35.850

Reputation: 283 655

20This does not work in Powershell - it will follow the junction and delete all files. Use cmd /c "rmdir mydir". – Brian Low – 2014-09-15T06:00:52.503

1@BrianLow: Wat. – user1686 – 2014-09-15T06:29:07.183

3

@grawity Seems to for me: https://gist.github.com/brianlow/0d5d2070c87c378454d7

– Brian Low – 2014-09-16T01:46:46.210

1rmdir tells dir is not empty for junction – Sergey – 2018-10-16T16:34:31.733

2@gravity, thanks! rd works while del does not. – Nord – 2011-05-19T05:45:27.760

Owh.. I mean @grawity (not @gravity) in my previous comment. Please accept my apology. – Nord – 2011-05-19T05:53:49.033

6As a Linux user I really struggled to find this. Thanks so much! – Jonathon Reinhart – 2011-10-28T01:05:19.370

2@JonathonReinhart I resonate well with that. If only Windows started used swap and ext4 without third-party software! – mjohnsonengr – 2012-08-15T16:02:21.793

5@Vi3GameHkr: If only Linux started using ntfs without third-party software... /// Windows does use swap, it just calls it "paging file". – user1686 – 2012-09-07T13:05:59.497

Thanks :) This works fine. I didn't want to do it in Explorer as it may delete the target stuff too. – Adambean – 2013-08-23T14:40:51.937

For some reason this didn't work for me. I had to do the following in a console with administrator privileges first: fsutil reparsepoint delete C:\Path\To\Junction – Zugwalt – 2014-03-27T16:55:36.540

20

In my experience fsutil reparsepoint will take care of some cases where rmdir gives Access Denied.

fsutil reparsepoint delete <<PATH>>

Spig

Posted 2011-05-19T04:14:35.850

Reputation: 301

I had a junction point that was giving access denied if I used rmdir. Using this method, the junction point becomes a regular folder with read-only attribute. attrib -R and rmdir finally finished the job. – Codism – 2016-10-28T15:06:19.457

10

Use the -d flag on junction (junction -d ...)

Source: http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx

Jeff G

Posted 2011-05-19T04:14:35.850

Reputation: 101

-1

linkd source /D

will delete the junction point (the link) without deleting on destination

Nicolas

Posted 2011-05-19T04:14:35.850

Reputation: 39

7Read the question. This command doesn't exist in Windows 7. – Aaronaught – 2013-11-24T17:27:08.023