How do you make a symbolic link with a relative path using mklink?



Symbolic links, known as symlinks, are virtual files or folders that point to other files or folders stored on the same computer or a network. Symlinks are used to create shortcuts and enable users to access files and folders that are stored in different locations. Symlinks are often used to make files and folders easier to access, or to share files and folders between computers on a network.

The Windows command for creating a symbolic link is MKLINK. The basic syntax for this command is mklink [source] [destination], where source is the file or folder that you want to link to and destination is the file or folder where the link should be created.

When creating a symbolic link with MKLINK, you can use either absolute or relative paths. An absolute path is a complete path that includes the root directory and the full directory structure. A relative path is a path that is relative to the current directory. In other words, it does not include the root directory, but only the directories between the current directory and the destination.

When creating a symbolic link with MKLINK, you can use a relative path by using a period (.) to refer to the current directory and two periods (..) to refer to the parent directory. For example, if you want to create a symbolic link from C:\\Source\\Folder1\\Myfile.txt to C:\\Destination\\Folder2\\Myfile.txt, you could use the following command:

mkLINK .\\Folder1\\Myfile.txt ..\\Folder2\\Myfile.txt

This command will create a symbolic link from C:\\Source\\Folder1\\Myfile.txt to C:\\Destination\\Folder2\\Myfile.txt. The period (.) in the source path refers to the current directory (C:\\Source). The two periods (..) in the destination path refer to the parent directory (C:\\Destination).

It is important to note that when using MKLINK with a relative path, the path is always relative to the current directory. For example, if you are in the C:\\Destination directory and you try to use the same command as above, the command will fail because the source path will not be found in the C:\\Destination directory.

When creating a symbolic link with MKLINK, you should always use the absolute path whenever possible. This is because relative paths can be difficult to manage and can cause issues if the directory structure changes. In addition, relative paths can be more difficult to understand.

In summary, the Windows command for creating a symbolic link is MKLINK. You can use either an absolute or relative path with this command. If you are using a relative path, you should use a period (.) to refer to the current directory and two periods (..) to refer to the parent directory. Whenever possible, you should use an absolute path when creating a symbolic link with MKLINK. This will help ensure that the link is created correctly and that it will not be affected if the directory structure changes.

Inquire Now

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Find your next full or part-time role here

ScaleDesk can either help you find your next full time gig or a part time side gig where you can create extra income!

Onboard with us once
Skip HR screening and go to the final interview with with only your resume and a video interview you never have to redo
Get paid electronically every month for the hours you work
We will be your reference even if you work for us once

IT Teams: Use ScaleDesk to augment your team

Schedule Demo