22. October 2011 · 6 comments · Categories: Windows · Tags:
Hard Links, Junction Points and Symbolic Links are linking mechanisms used to refer to other files, directories, or volumes. Generally, a Hard Link is a file that acts like a representation of another file on the same drive without actually duplicating that file. A Junction Point (or directory hard link) is a type of hard link that acts like a representation of a directory, a partition or another volume. A Symbolic Link (or soft link) is a file similar to a shortcut in that it points to a filename or directory name, but it’s handled at the system level rather than at the application level. Often confused with shortcuts as well as with each other, Hard links, Symbolic links and Junction Points are not the same; although like shortcuts, deleting either links or junction points usually won’t delete the target and vice versa (see exceptions below). Of the three, Symbolic Links are more similar to shortcuts than either Hard links or Junction Points, and they are generally more flexible, easier to use, and safer. When given a choice, most professionals recommend using Symbolic Links.

Although Symbolic Linking has been around since 1978 and shortly thereafter standardized in UNIX and UNIX-like Operating Systems, it’s been present in Windows only since Vista. Symbolic Linking was introduced in Vista to replace Hard Links and Junction Points and to enhance compatibility with UNIX and UNIX-like systems. Hard Linking for files and support for directory hard links (Junction Points) have been present in Windows since Win2K – often using different implementations in each succeeding Windows version. Because the development of linking in Windows has been relatively recent and ongoing, a number of different linking methods have been included, supported, or made available as third-party add-ons depending on the Windows version. Currently, Hard Links, Junction Points and Symbolic Links in Windows are only supported for the NTFS file system. Note that Windows does not support Hard Links or Junction Points to directories on remote shares; however, Symbolic Links can point to remote files and directories on SMB network paths.

Hard Links, Junction Points, Symbolic Links, and Shortcuts are further contrasted below:

Hard Link (Linking for individual files):

  • A file that acts like a representation of a target file on the same drive
  • Has the same size as the target without duplicating it (doesn’t use any space)
  • Interpreted at the operating system level (SW apps can act upon the target through the link)
  • Deleting the Hard Link does not remove the target file
  • If the target is deleted, its content is still available through the hard link
  • Changing the contents through the Hard Link changes the target contents*
  • Must reside on the same partition as the target file
  • Compatible with Win2k and above in Windows

* Some text editors save changed text to a new file and delete the original file, which can break the link. This behavior can be changed in some editors by forcing a save over the original file instead. See discussion at Jameser’s Tech Tips here for more information.

Junction Point (Directory Hard Link):

  • A file that acts like a representation of a target directory, partition or volume on the same system
  • Has the same size as the target without duplicating it (doesn’t use any space)
  • Interpreted at the operating system level – transparent to SW programs and users
  • Deleting the Junction Point does not remove the target*
  • If the target is moved, renamed or deleted, the Junction Point still exists, but points to a non-existing directory
  • Changing the contents through the Junction Point changes the target contents
  • Can reside on partitions or volumes separate from the target on the same system
  • Compatible with Win2k and above in Windows

*A Junction Point should never be removed in Win2k, Win2003 and WinXP with Explorer, the del or del /s commands, or with any utility that recursively walks directories since these will delete the target directory and all its subdirectories. Instead, use the rmdir command, the linkd utility, or fsutil (if using WinXP or above) or a third party tool to remove the junction point without affecting the target. In Vista/Win7, it’s safe to delete Junction Points with Explorer or with the rmdir and del commands.

Symbolic Link (Soft Link):

  • A file containing text interpreted by the operating system as a path to a file or directory
  • Has a file size of zero
  • Interpreted at the operating system level – transparent to SW programs and users
  • Deleting the Symbolic Link does not remove the target
  • If the target is moved, renamed or deleted, the link still exists, but points to a non-existing file or directory
  • Points to, rather than represents, the target using relative paths
  • Can reside on partitions or volumes separate from the target or on remote SMB network paths
  • Compatible with UNIX and UNIX-like systems and with Vista and above in Windows

Shortcut:

  • A file interpreted by the Windows shell or other apps that understand them as paths to a file or directory
  • File size corresponds to the binary information it contains
  • Treated as ordinary files by the operating system and by SW programs that don’t understand them
  • Deleting the shortcut does not remove the target
  • Maintains references to target even if the target is moved or renamed, but is useless if the target is deleted
  • Points to, rather than represents, the target
  • Can reside on partitions or volumes separate from the target on the same System
  • Compatible with all Windows versions

Windows Applications for Creating Links:

A number of applications are available for creating links in Windows including those bundled with the operating system and third-party tools. Some of the more well known are summarized below.

Utilities included with Windows:

  • fsutil – a command line tool included with WinXP and above. It can only create Hard Links for files – it doesn’t create directory hard links (Junction Points) or Symbolic Links. Further information about this tool is available at Commandwindows.com.

usage: FSUTIL hardlink create new_filename existing_filename

  • mklink – a command line tool included with Vista and Server 2008 and above. The most current link creation tool included with Windows. It creates Hard Links, Symbolic Links and Junction Points.

usage: mklink [[/d] | [/h] | [/j]] <NameofLink> <Target>

/d – Creates a Symbolic Link for a directory. If no flag used, creates a Symbolic Link for a file (default)

/h – Creates a Hard Link

/j – Creates a Junction Point

<NameofLink> – The name for the Symbolic Link being created

<Target> – The relative or absolute path of the target

/? – Help

Third-party Tools:

Command line tools:

  • junction.exe – by Sysinternals  – Creates Junction Points and includes additional commands for displaying and deleting them. Runs on Windows XP and higher and Windows Server 2003 and higher.

display reparse point* info usage: junction.exe [-s] [-q] <file or directory>

-q – Don’t print error messages (quiet)

-s – Recurse subdirectories

create usage: junction.exe <junction directory> <junction target>

delete usage: junction.exe -d <junction directory>

*Reparse points are redirections in the Windows file system using user-defined data in tags to identify and process files.

  • linkd.exe – Part of the Windows 2003 Resource Kit  – Creates and deletes Junction Points. (For Win2k, WinXP and Windows Server 2003)

create usage: linkd newdirname existingdirname

delete usage: linkd newdirname /D

Context Menu/Shell tools:

  • NTFS Linkelsdoerfer.name – Creates Hard Links and Junction Points using drag and drop with the right mouse button. Works with Win2K (NTFS ver 5 or greater) and above.

GUI-based tools:

  • Junction Link Magic – Rekenwonder Software – GUI-based application to create, list, and remove Junction Points. Also lists Symbolic Links and Mount Points. Works with Win2K, XP, 2003, Vista, Windows Server 2008 and Windows 7.

Tutorials on creating and using Hard Links, Soft Links and Junction Points:

Daniel Einspanjer’s journal - How To Use Hardlinks And Junctions In Windows

The Developer’s TidbitWindows File Junctions, Symbolic Links and Hard Links

How-to GeekUsing Symlinks in Windows Vista

Jameser’s Tech TipsTip #37: Creating NTFS Hard Links in Windows XP

Jeff Wouters’s BlogMaking soft and symbolic links in Windows

Maxi-Pedia – Mklink in Windows

TechRepublic – Vista’s symbolic links feature saves navigating time

 

Share

6 Comments

  1. jalle says:

    I have created hardlink clone of user system folder, by mistake of course.
    rmdir doesnt help also tried using UnlockIT to unlock file but no success.

    How do I remove lock of those system files
    AND
    remove Hardlink clone folder completely?

  2. Another Anonymous says:

    Junction point can point only to directory, so of course my last sentence should have been “- – – points to a non-existing directory”

  3. Another Anonymous says:

    You wrote about Junction Point:
    – If the target is deleted, its content is still available through the Junction Point

    According to my testing this is not true and maybe you should change the line to these two:

    – If the target is deleted, its content is not available through the Junction Point
    – If the target is moved, renamed or deleted, the Junction Point points to a non-existing file or directory

  4. Anonymous says:

    symlink is very important while working in unix. you can also update symblink in one step check this update soft link in unix in one step

Bear

Bad Behavior has blocked 539 access attempts in the last 7 days.