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

Linux - 硬链接(Hard Links)和符号链接(Symbolic Links)

硬链接(Hard Links)和符号链接(Symbolic Links) 本文地址:
  • u012515223
  • u012515223
  • 2014年03月20日 09:30
  • 4871

硬连接(hard link)和软连接(symbolic link)

stat - display file or file system status struct stat { mode_t       st_mode;    /* file type & ...
  • jiangxt211
  • jiangxt211
  • 2017年02月25日 16:47
  • 437

ln 命令用法 hard link 与 symbolic link 区别 分析

Hard Link (实体链接, 硬式连接)     首先要知道inode。它就像一个指向档案的指针,档案的内容由inode的记录来指向。所以读取一个档案内容可以有多个文件名对应一个文件的ino...
  • fansongy
  • fansongy
  • 2011年08月17日 20:30
  • 5617

ln: Too many levels of symbolic links

使用ln创建链接时,参数source的写法很重要。如果source与target不是在同一目录,那么source的路径应该使用显示路径,否则会出现Too many levels of symbolic...
  • ani_di
  • ani_di
  • 2012年07月19日 14:39
  • 4194

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

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

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

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


#define EPERM 1 /* Operation not permitted */ #define ENOENT 2 /* No such file or directory */ #...
  • luotuo44
  • luotuo44
  • 2014年01月03日 00:12
  • 1333

centos 创建软连接后,打开软连接文件,报错:Too many levels of symbolic link

centOS上,装了sublime text3。为了方便在终端使用编辑器,我切换到/opt/sublime_text_3/sublime_text/目录,然后,使用命令#ln -s ./sublime...
  • misakaqunianxiatian
  • misakaqunianxiatian
  • 2016年07月24日 23:57
  • 1697


前言:在Win7下安装了VMware+Ubuntu,现在想阅读Linux内核代码。首先想到的是使用Source Insight,它是一款非常优秀的代码阅读工具。但Source Insight是运行在W...
  • zhuxiaoyang
  • zhuxiaoyang
  • 2011年10月09日 10:02
  • 2406

mac 10.10.4 编译nginx1.9.5遇到的问题

环境信息: MACOS 版本:10.10.4 Nginx:nginx-1.9.5 Openssl:openssl-1.0.0e Pcre:pcre-8.32 Zlib:zlib-1.2.8 ...
  • wgw335363240
  • wgw335363240
  • 2015年12月30日 10:41
  • 1874
您举报文章:Windows File Junctions, Symbolic Links and Hard Links