- Symlinks in Windows 10!
- Overview
- Background
- What drove this change?
- How to use Symlinks
- How do I try it?
- How are Windows symbolic links treated by the apps?
- 3 Answers 3
- How can I create a symbolic link on Windows 10?
- 6 Answers 6
- It seems like the junction command has been retired in Windows 10.
- So how do I create junctions or directory symbolic links in Windows 10?
- Examples
- Further Reading
- How to Create Symbolic Links (Symlink) in Windows 10
- What Are Symbolic Links?
- Create Symbolic Link Using Link Shell Extension
- Create Symbolic Link Using Mklink
Symlinks in Windows 10!
Overview
Symlinks, or symbolic links, are “virtual” files or folders which reference a physical file or folder located elsewhere, and are an important feature built in to many operating systems, including Linux and Windows.
The Windows’ NTFS file system has supported symlinks since Windows Vista. However, it hasn’t been easy for Windows developers to create symlinks. In our efforts to continually improve the Windows Developer experience we’re fixing this!
Starting with Windows 10 Insiders build 14972, symlinks can be created without needing to elevate the console as administrator. This will allow developers, tools and projects, that previously struggled to work effectively on Windows due to symlink issues, to behave just as efficiently and reliably as they do on Linux or OSX.
Background
A symlink is essentially a pointer to a file or folder located elsewhere, consumes little space and is very fast to create (compared to copying a file and its contents).
Because of this, developers often replace duplicate copies of shared files/folders with symlinks referencing physical files/folders. Replacing redundant copies of files can save a great deal of physical disk space, and significantly reduce the time taken to copy/backup/deploy/clone projects.
In UNIX-compatible operating systems like Linux, FreeBSD, OSX, etc., symlinks can be created without restrictions.
However, for Windows users, due to Windows Vista’s security requirements, users needed local admin rights and, importantly, had to run mklink in a command-line console elevated as administrator to create/modify symlinks. This latter restriction resulted in symlinks being infrequently used by most Windows developers, and caused many modern cross-platform development tools to work less efficiently and reliably on Windows.
Now in Windows 10 Creators Update, a user (with admin rights) can first enable Developer Mode, and then any user on the machine can run the mklink command without elevating a command-line console.
What drove this change?
The availability and use of symlinks is a big deal to modern developers:
Many popular development tools like git and package managers like npm recognize and persist symlinks when creating repos or packages, respectively. When those repos or packages are then restored elsewhere, the symlinks are also restored, ensuring disk space (and the user’s time) isn’t wasted.
Git, for example, along with sites like GitHub, has become the main go-to-source code management tool used by most developers today.
Figure 1: SCM Tool Trends 2004-2016 (Source, Google)
The use of package managers in modern development has also exploded in recent years. For example, node package manager (npm) served
400 million installs in the week of July 1 st 2015, but served more than 1.2 billion installs just one year later – a 3x increase in just one year! In late June 2016, npm served more than 1.7 billion node packages in just seven days!
Figure 2: npm served 1.2Bn downloads in the first week of July 2016
There are clear drivers demanding that Windows enables the ability to create symlinks to non-admin users:
- Modern development projects are increasingly portable across operating systems
- Modern development tools are symlink-aware, and many are optimized for symlinks
- Windows developers should enjoy a development environment that is at least the equal of others
How to use Symlinks
Symlinks are created either using the mklink command or the CreateSymbolicLink API
mklink
- There is no change in how to call mklink. For users who have Developer Mode enabled, the mklink command will now successfully create a symlink if the user is not running as an administrator.
CreateSymbolicLink
- To enable the new behavior when using the CreateSymbolicLink API, there is an additional dwFlags option you will need to set:
Value | Meaning |
SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE 0x2 | Specify this flag to allow creation of symbolic links when the process is not elevated |
Example Use
In the example below:
- A subfolder folder called “animals” containing three files (cat.txt, dog.txt, and fish.txt)
- (green) The mklink command is executed to create a symlink called “pet.txt” pointing at the “animalsdog.txt” file
- (blue) When the contents of the current folder are listed, the symlink can be seen (yellow)
- (purple) When contents of pet.txt are queried, the content of the referenced file (“dog.txt”) is displayed
Once created, symlinks can be opened, loaded, deleted, etc., just like any other file. Here, the pet.txt symlink is being opened in Notepad (red):
How do I try it?
This new symlinks support first shipped in Windows 10 Insiders Build 14972, and will be formally delivered in Windows 10 Creators Update. We are also working with the owners of open-source community tools such as Git and npm so they know symlink improvements are coming and can make the necessary changes to better support symlinks on Windows.
We encourage you to take this new feature for a spin and be sure to let us know via the Windows 10 Feedback hub or on Twitter etc. (see below). Please sign up for the Windows Insiders program if you haven’t already to try out symlinks!
How are Windows symbolic links treated by the apps?
I thought that symbolic links in Windows 10 behave similarly to Linux symlinks, i.e., they are transparent to the apps. However, I’m confused by the actual behavior.
As an example, I’ve both softlinked and hardlinked the same CSS file:
The hardlink behaves predictably (is indistinguishable from the original file) but I don’t understand the soft linked one. See for example this:
Also, when the CSS is consumed by the Caret editor, the hardlinked stylesheet works fine:
while the softlinked is broken:
The questions are:
- How do the symbolic links actually behave on Windows?
- Can soft links be made transparent to the apps? By transparent, I mean the app would always see the file as being on the symlinked path ( . \symlinked.css ) and never resolve to the original path ( . \Default.css ). Is there some Windows registry settings or something?
3 Answers 3
Symlinks are transparent to applications that are using the underlying file system, e.g., CreateFile() and friends, unless the application makes a specific effort to be aware of them.
However, they are not transparent to applications that are using the shell namespace (for example the standard Open File dialog) because the shell treats symlinks as if they were shortcuts, even to the point of modifying the displayed icon. Whether this was a sensible decision on Microsoft’s part is a moot point at this stage, since it isn’t about to change. So far as I’m aware, it is not configurable.
In practice this usually means that symlinks will behave transparently for non-GUI applications and for internal files (DLLs, built-in templates, configuration files, etc.) in GUI applications, but not for the user’s documents.
So your first two examples (the way Explorer displays the files and the behaviour of Notepad++) are features rather than bugs; like it or not, this is the way Windows is designed to work.
Your last example does appear to be a bug (or at best an undesirable design limitation) in the application in question. It might be worth contacting the vendor.
You should also be aware that creating a symlink requires administrative privilege, and by default they don’t work at all over network shares. Personally, given all these limitations, I’ve never found them very useful. For most user tasks I would use shortcuts instead, and for most system administration tasks junction points are more reliable.
How can I create a symbolic link on Windows 10?
I was reading http://www.dropboxwiki.com/tips-and-tricks/sync-game-saves-across-multiple-computers, and I know junction/mklink worked in Windows 7 as well, but it seems like the junction command has been retired in Windows 10.
What’s the correct way to make symbolic links in Windows 10?
6 Answers 6
It seems like the junction command has been retired in Windows 10.
You can download junction from Windows SysInternals (which is part of Microsoft):
Junction not only allows you to create NTFS junctions, it allows you to see if files or directories are actually reparse points. Reparse points are the mechanism on which NTFS junctions are based, and they are used by Windows’ Remote Storage Service (RSS), as well as volume mount points.
Please read this Microsoft KB article for tips on using junctions.
Note that Windows does not support junctions to directories on remote shares.
So how do I create junctions or directory symbolic links in Windows 10?
Download junction as instructed above.
Now you can use the following commands.
Create a junction:
Create a directory symbolic link:
You can use either mklink /j or junction in Windows 10 to create junctions.
You can use mklink /d in Windows 10 to create directory symbolic links.
junction can also list junctions and determine if a file is a junction unlike mklink .
mklink is an internal command only available within a cmd shell.
By default Administrator privileges are required to create symbolic links.
It can also be granted to other users. The security setting «Create symbolic links» can be granted at:
Examples
Using mklink to create a directory symbolic link:
Using mklink to create a junction:
Using junction to create a junction:
Further Reading
- An A-Z Index of the Windows CMD command line — An excellent reference for all things Windows cmd line related.
- mklink — Create a symbolic link to a directory or a file, or create a hard file link or directory junction.
Open a PowerShell session as elevated administrator and type:
or using less verbose syntax:
Surely in 2016 and with Windows 10 you don’t want to fiddle around with cmd commands or external downloads.
Windows 10 comes with PowerShell 5 which has builtin support for creating symbolic links.
Link Shell Extension (LSE) provides for the creation of Hardlinks , Junctions , Volume Mountpoints , and Windows7/8’s Symbolic Links, (herein referred to collectively as Links) a folder cloning process that utilises Hardlinks or Symbolic Links and a copy process taking care of Junctions, Symbolic Links, and Hardlinks. LSE, as its name implies is implemented as a Shell extension and is accessed from Windows Explorer, or similar file/folder managers. The extension allows the user to select one or many files or folders, then using the mouse, complete the creation of the required Links — Hardlinks, Junctions or Symbolic Links or in the case of folders to create Clones consisting of Hard or Symbolic Links. LSE is supported on all Windows versions that support NTFS version 5.0 or later, including Windows XP64 and Windows7/8/10. Hardlinks, Junctions and Symbolic Links are NOT supported on FAT file systems, and nor is the Cloning and Smart Copy process supported on FAT file systems.
How to Create Symbolic Links (Symlink) in Windows 10
Symlinks or Symbolic Links is one of the lesser known, yet useful, features in Windows. You can think of symbolic links as the shortcuts you create in Windows. However, symbolic links are much more powerful and helpful than regular shortcuts. Let’s discuss what symbolic links are and how you can easily create them in Windows 10.
What Are Symbolic Links?
When you create a shortcut for a file or folder, all you are doing is pointing it to that specific file or folder, nothing more. Symbolic links are much more than a simple shortcut. They act as a virtual file or folder that links to the actual file or folder.
When you create a symlink for a file, it appears as if it is the actual file when in reality it is redirecting you toward the real file in the background. Besides files, you can also create symlinks for folders. Simply put, a symlink is nothing more than a build of the text string which lets the operating system know that it is just a path for another file or folder.
For instance, most cloud service apps you install will only sync files and folders located in their own folder. But there will be times when you might have a folder in some other drive you want to sync with the cloud storage service.
However, you don’t want to move the folder from its actual location or don’t want to create a copy of the folder. In those situations you can simply create a symlink in the cloud service folder so that you can sync the contents of the target folder without actually moving or copying the real folder.
Since a symlink is just a virtual folder that just acts as a path to the real folder, you don’t have to worry about the symlink consuming your disk space.
Create Symbolic Link Using Link Shell Extension
If you don’t want to faff around in the Command Prompt and are prepared to faff around a little bit by installing a tool that lets you create symlinks to an existing file or directory using the right-click context menu, then try the following. Link Shell Extension is a tool that lets you create hardlinks and symbolic links by right-clicking whatever folder you want to create a link to.
There are a few hoops with the installation. You’ll get a warning that it can’t be downloaded securely, and Windows Defender may warn you that it’s “unsigned.”
We can assure you that the tool is safe. Go ahead and install it. During installation, explorer.exe will restart, so make sure you have important stuff backed up.
Once LSE is installed, right-click the target file or folder you want to create a symlink to, then click “Pick Link Source.”
Next, go to the folder where you want the symlink to appear, right-click it, then select “Drop As -> Symbolic Link.”
Create Symbolic Link Using Mklink
Note: though I’m showing this in Windows 10, the commands shown here are applicable to Windows Vista and up.
Creating symlinks in Windows is pretty easy with the mklink command. To start, press Win + X , then select the option “Command Prompt (Admin)” to open the Command Prompt with admin rights.
Once the command prompt has been opened, use the below command format to create a symlink for a file.
In my case, I want to create a symlink in the E drive for a text file located on the F drive, so the command looks something like this:
The first path you see in the above command is where you will create your symlink. This path is called a “Link.” The second path belongs to the actual file on your disk and is called “Target.”
Once the symlink has been created, this is how it looks in the File Explorer. Though the icon looks like a regular shortcut, it is a symlink.
Along with individual files, you can create symlinks for entire directories. To do that, use the below command. The switch /D allows you to do this.
As soon as you execute the command, the symlink will be created for the target directory. You can use it to access all the files and folders inside the real folder. If you ever want to, you can delete the symbolic link like any other file or folder. Just select the symlink, press the delete key on your keyboard, and you are good to go.
And you’re done! If you want to do more under-the-hood tweaking in Windows 10, see our list of the best registry hacks. Also, check out our guide on how to get Mac-style hot corners in Windows 10.