命令行大全

mklink

小猪老师 发表于 2020-06-23 15:36浏览次数:

mklink命令用于通过Windows命令行创建符号链接。

查看英文版

目录:

1 mklink 运行系统环境

2 mklink 语法

3 mklink 示例

mklink 运行系统环境

Windows vista

Windows 7

Windows 8

Windows 10

mklink 语法

MKLINK [[/D] | [/H] | [/J]] Link Target
/D 创建符号目录链接。默认是符号文件链接。
/H 创建硬链接而不是符号链接。
/J 创建目录连接。
Link 指定新的符号链接名称。
Target 指定新链接的相对或绝对路径。
MKLINK [[/D] | [/H] | [/J]] Link Target
/D Creates a symbolic directory link. The default is a symbolic file link.
/H Creates a hard link instead of a symbolic link.
/J Creates a directory junction.
Link Specifies the new symbolic link name.
Target Specifies the path (relative or absolute) of the new link.

查看英文版

查看中文版

mklink 示例

mklink /d \Docs \Users\Hope\Documents

上面的示例命令将创建一个名为Docs的符号链接,指向\Users\Hope\Documents目录,即使该目录不存在。
如果链接成功创建,您将看到如下所示的消息。

Symbolic link created for \Docs <<===>> \Users\Hope\Documents

创建符号链接后,使用dir命令可以在创建它的目录列表中看到任何符号链接。
要进入符号链接目录,您可以像对待其他目录一样对待它,并使用cd命令。
要进入Docs目录,你可以在提示符中输入“cd Docs”,就好像它是一个目录一样。

如何创建一个连接点?

要创建到本地目录的连接点,请执行以下命令。
可以看出,我们使用的是/j开关而不是/d开关。

mklink /j example backup

如果成功创建,您将看到与下面示例类似的消息。

Junction created for example <<===>> backup

创建连接后,使用dir命令可以在连接创建位置的目录列表中看到任何连接。

如何创建一个符号链接或连接到一个目录与一个空间?

如果要链接或指向的文件或目录的名称中包含空格,则必须用引号括起来。
在下面的示例中,我们从当前目录创建到“c:\program files”目录的符号链接。

mklink /d files "c:\program files"  

如何删除符号链接?

要删除符号链接,请像处理其他目录或文件一样处理它。
如果您使用上面所示的命令创建了一个符号链接,移到根目录(因为它是“\Docs”)并使用rmdir命令。
如果创建了文件的符号链接(),要删除符号链接,可以使用del命令。

如何删除一个连接点?

一个连接点只会是一个目录,所以您只需要使用rmdir命令来删除它。

删除符号链接或连接点是否会删除链接的文件或目录?

不。
当您删除符号链接或连接点时,它只是删除链接或指针,而不是它所指向的文件或目录。
但是,如果您创建一个指向目录的符号链接或连接点,并打开该链接或指针并删除目录中的文件,那么这些文件将被删除。

mklink /d \Docs \Users\Hope\Documents

The example command above would create a symbolic link called Docs to the \Users\Hope\Documents directory, even if the directory does not exist.

If the link is successfully created, you will see a message similar to the one shown below.

Symbolic link created for \Docs <<===>> \Users\Hope\Documents

Once the symbolic link is created, using the dir command you can see any symbolic link in the directory listing of where it was created.

Below is an example of what the previous symbolic link directory,, would look like in the command line.

To get into the symbolic link directory, you would treat it like any other directory and use the cd command. To get into the Docs directory, you would type "cd docs" at the prompt as if it was a directory.

How do I create a junction point?

To create a junction point to a local directory, perform the following command. As can be seen, we are using the /j switch instead of the /d switch.

mklink /j example backup

If created successfully, you will see a message similar to the example shown below.

Junction created for example <<===>> backup

Once the junction is created, using the dir command you can see any junction in the directory listing of where the junction was created. Below is an example of what the above junction directorywould look like in the command line.

How do I create a symbolic link or junction to a directory with a space?

If the file or directory you want to link or point to contains a space in its name, it must be surrounded with quotes. In the example below, we are creating a symbolic link to the "c:\program files" directory from the current directory.

mklink /d files "c:\program files"

How do I delete a symbolic link?

To delete a symbolic link, treat it like any other directory or file. If you created a symbolic link using the command shown above, move to the root directory since it is "\Docs" and use the rmdir command. If you created a symbolic link () of a file, to delete a symbolic link use the del command.

How do I delete a junction point?

A junction point is only going to be a directory, so you should only need to use the rmdir command to remove it.

Will deleting a symbolic link or junction point delete the linked files or directory?

No. When you delete a symbolic link or a junction point, it's only removing the link or pointer and not the file or directory to which it's pointing. However, if you create a symbolic link or junction point to a directory and open that link or pointer and delete files in the directory, those files will be deleted.


mklink命令要求您处于升高的命令提示符中。联结点只能链接到本地​​目录。

The mklink command requires you to be in an elevated command prompt. A junction point can only link to a local directory.

查看英文版

查看中文版