Mklink in Windows
Mklink in Windows
Mklink is a MS Windows command line utility that you can use to create symbolic links or symlinks and hard links in MS Windows. Mklink is a nice tool for troubleshooting file system problems. Mklink requires administrative privileges.
This page relates to explaining the difference between symbolic links and hard links on the Difference between symbolic link and hard link page.
First, let's introduce the mklink command. You can see it in the following print screen:
It is pretty self-explanatory. Now, let's take a look at an example.
Mklink example
The print screen shown below demonstrates creating symbolic links, hard links, and shortcuts in MS Windows and how they differ.
Symbolic link:
- Created as mklink link_name target_name
- The icon next to the link is the same like that of a shortcut
- Occupies zero space in the system
- It is not a separate file in the file system
- Interpreted at the operating system level
- If the original file is deleted, the link is useless
- Removing the original file does not remove the symbolic link
- Removing the symbolic link does not remove the original file
Hard link:
- Created as mklink /H link_name target_name
- The space it occupies equals the size of the original file, but refers to the same object in the system (not a copy)
- Interpreted at the operating system level
- The icon next to the hard link is different from the other objects
- Removing the original file does not remove the hard link
- Removing the hard link does not remove the original file
- If the original file is deleted, its content is still available through the hard link
- Making a change to the hard link propagates all changes to the original file
Shortcut:
- Created by right clicking the original file and selecting action from the drop down menu
- A file in the system that is completely separate from the original file
- Only those programs that know the concept of shortcuts understand them
- If the original file is deleted, the link is useless
- Removing the original file does not remove the shortcut
- Removing the shortcut does not remove the original file
The print screen below shows these concepts.
Linux uses a similar command called ln.
Mklink in Windows versus Ln in Linux
Note, the mklink syntax is a bit different from the Linux ln syntax (ln is used in Linux to create links).
Mklink: The name of the link is followed by the name of the target in the mklink command syntax. If you do not specify any flag, the mklink utility creates a symbolic link by default.
Ln: The name of the target is followed by the name of the link. If you want to create a symlink, you have to specifically include the -s flag.
It is easy, just include the code provided below into your HTML code.