Create Soft and Hard Symbolic Links in Windows  

Page 1 of 9 123 ... LastLast
    Create Soft and Hard Symbolic Links in Windows

    Create Soft and Hard Symbolic Links in Windows

    How to Create Soft and Hard Symbolic Links in Windows
    Published by Category: General Tips
    11 Jun 2023
    Designer Media Ltd

    How to Create Soft and Hard Symbolic Links in Windows


    There are three types of file links supported in the NTFS file system: hard links, junctions, and symbolic links. Otherwise known as Reparse Points.

    Hard Links can only be created for files. Any changes to that file are instantly visible to applications that access it through the hard links that reference it. Hard links do not support UNC paths (network paths that begin with \\). Hard links to a file will not have a shortcut arrow icon on them.

    Symbolic Links are soft links that are basically advanced shortcuts. You can create a symbolic link to a local or remote file, folder, or shares path, and that link will appear to be the same as the target source. Symbolic links do support UNC paths (network paths that begin with \\). When you open a symbolic link, you will be redirected to the target source. Symbolic links will have a shortcut arrow icon on them.

    Junctions (Directory Junction) are soft links that can only be created to a local folder (directory) path. Junction points make it appear as though folder (directory) actually exists at the location of the junction point, and your app won’t know any better. Junction points do not support UNC paths (network paths that begin with \\). Junction points will have a shortcut arrow icon on them.

    Deleting anything in the link/junction or target (source) folder will delete it in both folders.

    Deleting the hard link, symbolic link, or junction point itself will not delete anything in the target (source) folder.

    See also:

    A symbolic link can be helpful if say you wanted to sync a folder for a program. For example, if you have a program that must have its files stored at C:\Program Files and you want them stored at D:\My Location instead. You could move the original directory from C:\Program Files to D:\My Location, and create a symbolic link (soft or hard) at C:\Program Files (link) pointing to D:\My Location (target).

    This tutorial will show you how to create soft and hard symbolic links (symlinks) pointing to a file or folder in Windows 7, Windows 8, Windows 10, and Windows 11.

    If you have Developer Mode turned on in Windows 10, you will need to use the mklink command in a normal command prompt instead of the usually required elevated command prompt.



    Contents

    • Option One: Create Symbolic Link Pointing to File in Command Prompt
    • Option Two: Create Symbolic Link Pointing to Directory in Command Prompt
    • Option Three: Create Hard Link Pointing to File in Command Prompt
    • Option Four: Create Junction Point to Directory in Command Prompt
    • Option Five: Create Symbolic Link Pointing to File in PowerShell
    • Option Six: Create Symbolic Link Pointing to Directory in PowerShell
    • Option Seven: Create Hard Link Pointing to File in PowerShell
    • Option Eight: Create Junction Point Pointing to Directory in PowerShell
    • Option Nine: Delete Hard Link, Symbolic Link, or Junction Point






    OPTION ONE

    Create Symbolic Link Pointing to File in Command Prompt


    1 Open an elevated command prompt.

    2 Type the command below into the elevated command prompt, and press Enter. (see screenshot below)

    mklink "Link" "Source Target"

    Substitute Link in the command above with the full path with file name and extension you want created as a soft symbolic link at.

    Substitute Source Target in the command above with the full path of the existing file with extension that is the target (source) you want the soft symbolic link pointing to. This is the actual location where everything will be saved at.

    For example: mklink "C:\Users\Brink\Desktop\My Documents Link.txt" "C:\Users\Brink\Documents\My Document.txt"


    3 When finished, you can close the elevated command prompt if you like.

    Create Soft and Hard Symbolic Links in Windows-soft_symbolic_link_to_file_command_prompt.jpg






    OPTION TWO

    Create Symbolic Link Pointing to Directory in Command Prompt


    1 Open an elevated command prompt.

    2 Type the command below into the elevated command prompt, and press Enter. (see screenshot below)

    mklink /d "Link" "Source Target"

    Substitute Link in the command above with the full path of a folder (directory) you want created as a soft symbolic link at.

    Substitute Source Target in the command above with the full path of the existing folder (directory) that is the target (source) you want the soft symbolic link pointing to. This is the actual location where everything will be saved at.

    For example: mklink /d "C:\Program Files\Mozilla Firefox" "D:\Mozilla Firefox"


    3 When finished, you can close the elevated command prompt if you like.

    Create Soft and Hard Symbolic Links in Windows-soft_symbolic_link_to_directory_command_prompt.png






    OPTION THREE

    Create Hard Link Pointing to File in Command Prompt


    1 Open an elevated command prompt.

    2 Type the command below into the elevated command prompt, and press Enter. (see screenshot below)

    mklink /h "Link" "Source Target"

    Substitute Link in the command above with the full path with file name and extension you want created as a hard link at.

    Substitute Source Target in the command above with the full path of the existing file with extension that is the target (source) you want the hard link pointing to. This is the actual location where everything will be saved at.

    For example: mklink /h "C:\Users\Brink\Desktop\My Documents Link.txt" "C:\Users\Brink\Documents\My Document.txt"


    3 When finished, you can close the elevated command prompt if you like.

    Create Soft and Hard Symbolic Links in Windows-hard_link_to_file_command_prompt.jpg






    OPTION FOUR

    Create Junction Point to Directory in Command Prompt


    1 Open an elevated command prompt.

    2 Type the command below into the elevated command prompt, and press Enter. (see screenshot below)

    mklink /j "Link" "Source Target"

    Substitute Link in the command above with the full path of a folder (directory) you want created as a soft link at.

    Substitute Source Target in the command above with the full path of the existing folder (directory) that is the target (source) you want the soft link pointing to. This is the actual location where everything will be saved at.

    For example: mklink /j "C:\Program Files\Mozilla Firefox" "D:\Mozilla Firefox"


    3 When finished, you can close the elevated command prompt if you like.

    Create Soft and Hard Symbolic Links in Windows-hard_link_to_directory_command_prompt.png






    OPTION FIVE

    Create Symbolic Link Pointing to File in PowerShell


    1 Open an elevated PowerShell.

    2 Type the command below into the elevated PowerShell, and press Enter. (see screenshot below)

    New-Item -ItemType SymbolicLink -Path "Link" -Target "Source Target"

    Substitute Link in the command above with the full path with file name and extension you want created as a soft symbolic link at.

    Substitute Source Target in the command above with the full path of the existing file with extension that is the target (source) you want the soft symbolic link pointing to. This is the actual location where everything will be saved at.

    For example: New-Item -ItemType SymbolicLink -Path "C:\Users\Brink\Desktop\My Documents Link.txt" -Target "C:\Users\Brink\Documents\My Document.txt"


    3 When finished, you can close the elevated PowerShell if you like.

    Create Soft and Hard Symbolic Links in Windows-soft_symbolic_link_to_file_powershell.jpg






    OPTION SIX

    Create Symbolic Link Pointing to Directory in PowerShell


    1 Open an elevated PowerShell.

    2 Type the command below into the elevated PowerShell, and press Enter. (see screenshot below)

    New-Item -ItemType SymbolicLink -Path "Link" -Target "Source Target"

    Substitute Link in the command above with the full path of a folder (directory) you want created as a soft symbolic link at.

    Substitute Source Target in the command above with the full path of the existing folder (directory) that is the target (source) you want the soft symbolic link pointing to. This is the actual location where everything will be saved at.

    For example: New-Item -ItemType SymbolicLink -Path "C:\Program Files\Mozilla Firefox" -Target "D:\Mozilla Firefox"


    3 When finished, you can close the elevated PowerShell if you like.

    Create Soft and Hard Symbolic Links in Windows-soft_symbolic_link_to_directory_powershell.jpg






    OPTION SEVEN

    Create Hard Link Pointing to File in PowerShell


    1 Open an elevated PowerShell.

    2 Type the command below into the elevated PowerShell, and press Enter. (see screenshot below)

    New-Item -ItemType HardLink -Path "Link" -Target "Source Target"

    Substitute Link in the command above with the full path with file name and extension you want created as a hard link at.

    Substitute Source Target in the command above with the full path of the existing file with extension that is the target (source) you want the hard link pointing to. This is the actual location where everything will be saved at.

    For example: New-Item -ItemType HardLink -Path "C:\Users\Brink\Desktop\My Documents Link.txt" -Target "C:\Users\Brink\Documents\My Document.txt"


    3 When finished, you can close the elevated PowerShell if you like.

    Create Soft and Hard Symbolic Links in Windows-hard_link_to_file_powershell.jpg






    OPTION EIGHT

    Create Junction Point to Directory in PowerShell


    1 Open an elevated PowerShell.

    2 Type the command below into the elevated PowerShell, and press Enter. (see screenshot below)

    New-Item -ItemType Junction -Path "Link" -Target "Source Target"

    Substitute Link in the command above with the full path of a folder (directory) you want created as a hard link at.

    Substitute Source Target in the command above with the full path of the existing folder (directory) that is the target (source) you want the hard link pointing to. This is the actual location where everything will be saved at.

    For example: New-Item -ItemType Junction -Path "C:\Program Files\Mozilla Firefox" -Target "D:\Mozilla Firefox"


    3 When finished, you can close the elevated PowerShell if you like.

    Create Soft and Hard Symbolic Links in Windows-hard_link_to_directory_powershell.jpg






    OPTION NINE

    Delete Hard Link, Symbolic Link, or Junction Point


    1 Open File Explorer (Windows 8/10) or Windows Explorer (Windows 7).

    2 Navigate to the location of the link or junction point, and delete it. This will not delete the target (source) the link/junction points to.

    Do not delete the target (source) the link/junction points to. You only want to delete the link/junction itself.



    That's it,
    Shawn Brink






  1. Posts : 190
    Windows 10, 22H2 10.0.19045
       #1

    Thank you for the tutorial, works perfectly! Resolved the issue with the latest version of Thunderbird (v78) breaking all the extensions to sync the address book. Address book files moved to Dropbox, hard links created in the Thunderbird profile folder . . . done!
      My Computer


  2. Posts : 68,953
    64-bit Windows 11 Pro for Workstations
    Thread Starter
       #2

    Homer712 said:
    Thank you for the tutorial, works perfectly! Resolved the issue with the latest version of Thunderbird (v78) breaking all the extensions to sync the address book. Address book files moved to Dropbox, hard links created in the Thunderbird profile folder . . . done!
    I'm glad it could help.
      My Computers


  3. Posts : 2
    Win 10 Pro
       #3

    Great article with great detail in the tutorials. Thanks.

    I was wondering if links (soft/hard/junctions) could be used to mirror a folder between 2 drives?
    I keep my desktop & documents folders in their default locations on my nvme drive and have my OneDrive folder setup on my larger SSD D Drive - this is done deliberately.
    I have a batch file that runs automatically every afternoon after work that does a robocopy mirror from C:\Users\(Username)\ to my D:\OneDrive\ folder
    Could using links keep the files in C & D in sync? IF not, do you have any recommendations / suggestions as a better way of doing it than robocopy?

    Thanks
      My Computer


  4. Posts : 7,607
    Windows 10 Home 20H2
       #4

    Is Robocopy not good enough to serve your needs?
      My Computer


  5. Posts : 2
    Win 10 Pro
       #5

    if I can do something that is sync'ed almost immediately as soon as I've updated a file without 3rd party software or running a RC batch, then that would be a win
    but no, there's no other reason for not using RC
    I'm always exploring ways of doing similar tasks better or with less resources / end user interaction
      My Computer


  6. Posts : 56,830
    Multi-boot Windows 10/11 - RTM, RP, Beta, and Insider
       #6

    daryllg said:
    if I can do something that is sync'ed almost immediately as soon as I've updated a file without 3rd party software or running a RC batch, then that would be a win
    but no, there's no other reason for not using RC
    I'm always exploring ways of doing similar tasks better or with less resources / end user interaction
    Thinking out loud....

    You can use hardlinks in the "D" drive folder, but that's not really syncing. No data is moving anywhere. The pointers (sym links in D) are just that, pointers. As an example, Windows uses hardlinks all over the Windows and Windows\System32 folders. They all point to data in Winsxs, for the most part.

    Only isue I can think of is how would OneDrive react to a hardlink. I've never tried that. Never dropped a symlink (hard) into a OneDrive folder that is already syncing to the Cloud. Go ahead and try one, see what happens. ONE, not a whole bunch!
      My Computers


  7. Posts : 7,607
    Windows 10 Home 20H2
       #7

    daryllg said:
    if I can do something that is sync'ed almost immediately as soon as I've updated a file without 3rd party software or running a RC batch
    I'm afraid Windows has no built-in app that performs real-time file synchronization between two drives. Hopefully, I am wrong.
      My Computer


  8. Posts : 56,830
    Multi-boot Windows 10/11 - RTM, RP, Beta, and Insider
       #8

    Matthew Wai said:
    I'm afraid Windows has no built-in app that performs real-time file synchronization. Hopefully, I am wrong.

    File History comes close, but not for what he wants.
      My Computers


  9. apb
    Posts : 94
    win 7 64bit
       #9

    symlink files into dirs?


    Is there a way to create a file symbolic link in an existing directory, without specifying the file name? For example,

    mklink linkdir sourcefile

    does not work, because mklink considers you are trying to make the symbolic link called "linkdir" and linkdir already exists, and what is more it is a directory.

    It would be nice if the above syntax created a file symlink called "sourcefile" in the directory "linkdir". How to do that?


    (Note that I need to do this not once, but dozens of times for a whole list of files, so entering the filename manually is not an option.)

    It would be analogous to the command

    copy sourcefile linkdir

    Thanks.

    --peter
      My Computers


 

Tutorial Categories

Create Soft and Hard Symbolic Links in Windows Tutorial Index Network & Sharing Instalation and Upgrade Browsers and Email General Tips Gaming Customization Apps and Features Virtualization BSOD System Security User Accounts Hardware and Drivers Updates and Activation Backup and Restore Performance and Maintenance Mixed Reality Phone


  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 17:16.
Find Us




Windows 10 Forums