Windows File Junctions, Symbolic Links and Hard Links

转载 2012年03月22日 23:17:04

Windows File Junctions, Symbolic Links and Hard Links

Rate This

Linux and Unix for a long time have had the marvellous ability for you to create hard links. For Window users unfamiliar with hard links, they not are unlike file and folder shortcuts. Except for one critical difference they are sorted and registered by the operating system’s file partition just like real files and directories. This means that unlike a shortcut, any program or application (including Windows Explorer and the Command Prompt) that looks that the hard link will always treat it the same as the original file or folder the symbolic link is pointing to.

Now this is advantageous for a number of reasons especially if you use multiple partitions on your computer. I for example keep all my work related files on a separate partition labelled with the W: drive. This allows me to optimise searches and backups as well as keeping the partition more secure from potential problems arising from operating system errors.

Part of my work involves web development and often that requires the files I am working on to be located on the web server’s root directory. This can be a problem if the web server application is installed on the C: drive. This is where a hard link is useful as I can simply create a link from the web server’s root directory and point it to the folder containing the HTML files on my work drive (W:). With the link the web server is none the wiser. Once I have finished developing, testing and troubleshooting I can remove the hard link and the web server will then assume the directory with the work has been removed. But this has been done without any directory refactoring or moving.

The Windows NTFS file system has supported some form of symbolic linking since Windows 2000. Unfortunately each revision of Windows up until Windows Vista has used a different method of implementing linking. So for this article I will just focus on the Windows Vista and the identical Windows 7 implementation.

So in Windows what is the difference between a short-cut and symbolic link (sym-link) and a hard link?

short cut is basically a file that points to another file. It is an antiquated, pointing system from the Windows 95 era. Shortcuts not only use up space on your hard drive, they linger around after the item they are pointing to has been deleted and may break if the destination is renamed or moved.

A symbolic link is like a short cut but instead of being saved as a file, they are registered to the file system. This means they do not use hard disk space but programs recognise and can read where the link is pointing to. A symbolic link can point to any file or folder either locally on the computer and over a network using a SMB path.

A file hard link and the directory junction are a little different. It not only points to the item but duplicates it as a copy without taking up the extra hard disk space required by a clone. If you have a hard link pointing to a file then delete the original file, the hard link will still retain a copy of the clone. One limitation of the file hard link is that the link can only be made on the same file partition as the file.

Finally a junction is a hard link for directories. To me they are the most useful and unlike their file hard links counterparts you can create junctions on different partitions. Again a junction is stored on the file system where it does not take up additional space and is treated by the operating system and programs as a local folder.

Windows Vista/7 uses the command line program called mklink to create these symbolic links. It has 3 arguments and then requires both a link name and target.

mklink /D /H /J [LINK NAME] [TARGET]

There are 4 modes for mklink and they all counteract each other meaning you can only use one argument or none at all.

No arguments creates file symbolic link which is like a shortcut that is registered on the file system instead of stored in a file.

/D creates a directory symbolic link which is like a shortcut that is registered on the file system instead of stored in a file.

/H creates what Windows refers to as a hard file link. A hard file link is used where you need multiple copies of a file but wish to save space by keeping only one physical copy on disk.

/J creates a Windows Junction which is a directory hard link. If you need duplicate copies of a directory but don’t wish to use up the extra hard drive space you can create a junction. Though be careful as any changes you make to a file or folder in one of the junction will affect all the others.

mklink /J WindowsVista C:\Windows

Would make a Windows Junction titled WinVista linking to the directory C:\Windows

Below is a screen capture of the 4 different types of symbolic and hard links. The yellow is a hard file link that doesn’t use up any extra hard drive space. The blue is a symbolic link to a file. The green is a symbolic link to a filedirectory. The red is a hard link to a directory which is known as a Windows directory junction.

Windows Vista MKLINK

Windows File Junctions, Symbolic Links and Hard Links


understanding hard links and symbolic links in Linux.

Hard Links Hard links are the original Unix way of creating links, compared to symbolic links, whic...

angular2搭建环境+部署项目以及创建新组件to many symbolic links encountered的问题

1,nodejs官网下载安装包,最新版的带有npm,下载一个就好 2,安装在默认位置,新建一个nodejs目录进行安装 3,添加环境变量,cmd进入安装目录,输入path可以看到环境变量 4,输入...
  • z_ssi
  • z_ssi
  • 2017年10月20日 13:18
  • 192

【翻译自mos文章】oracle支持在RDBMS HOME 下的 符号链接( Symbolic Links)吗?

oracle支持在RDBMS HOME 下的 符号链接( Symbolic Links)吗?

使用Symbolic Links以支持数据分区存储

MySQL数据库及表(仅MyISAM)支持符号链接(symbolic link),即数据库或表可以存储在my.cnf中指定datadir之外的分区或目录。 要支持符号链接,需要在配置中设置sym...
  • halou90
  • halou90
  • 2015年12月03日 14:13
  • 298

An error caused by symbolic links pointing to each other

ssh issue.

软链接ln -s以及如何解决其产生“Too many levels of symbolic links ”的错误?

Q1:如何利用ln -s来创建快捷方式? A1:ln(link,链接文件): Windows中的快捷方式,实际上快捷方式和它指向的文件是独立的两个文件,两个都占硬盘空间,只不过用户访问快捷方式时,其效...

ntfs hard links creator

  • 2014年06月25日 10:05
  • 13KB
  • 下载

【转】Hard links and Soft links详解


Excel Macros, Links and Other Good Stuff

  • 2008年08月27日 14:07
  • 387KB
  • 下载
您举报文章:Windows File Junctions, Symbolic Links and Hard Links