找回密码
 立即注册

QQ登录

只需一步,快速开始

教程经验总索引TVMW5/小日本5 索引【视频转换】小日本4/TE4XP 索引【视频转换】TAW4 / TDA3 索引【DVD打包软件】
Nero 索引DVD-Lab 索引【DVD打包软件】编解码器 索引 【必读】固顶帖011号
查看: 8365|回复: 0

[教程] 详解 Mklink 命令:在 Windows Vista / Win7 中使用符号链接

[复制链接]

9328

威望

303

金钱

1万

贡献

管理员

自由的灵魂

积分
99879
主题
5265
回帖
26223
注册时间
2003-4-10
最后登录
2024-4-27
发表于 2010-8-4 14:32:41 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
本帖最后由 IsaacZ 于 2010-8-5 01:33 编辑

转自:http://www.howtogeek.com/howto/windows-vista/using-symlinks-in-windows-vista/



翻译:IsaacZ


One of the long-awaited features in Windows Vista was the ability to use symbolic links, the way you can in linux. Sadly, they don’t work quite as well as they could, but it’s a big upgrade from prior versions, and has solved a number of problems for me already.
对 Windows Vista 一个长久期待的功能就是能像在 linux 中那样使用符号链接(symbolic links)。尽管他们工作得并不像我们想象得那样好,相比以往的操作系统来说,已经是大大的进步,并且已经解决了我不少问题。



Using the mklink Command
使用 mklink 命令

The command that you need to use is mklink, which you’ll use from the command line. Just type it on the command line to see the options:
你需要使用的命令是 mklink,这是一个在DOS命令行运行的命令。直接在命令提示符后键入此命令并回车即可看到相关选项参数:

C:\Users\geek>mklink
Creates a symbolic link.

MKLINK [[/D] | [/H] | [/J]] Link Target
        /D      Creates a directory symbolic link.  Default is a file
                symbolic 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) that the new link
                refers to.

在IsaacZ的中文版Win7下显示为:

C:\Users\IsaacZ>mklink
创建符号链接。
MKLINK [[/D] | [/H] | [/J]] Link Target
        /D      创建目录符号链接。默认为文件
                符号链接。
        /H      创建硬链接,而不是符号链接。
        /J      创建目录联接。
        Link    指定新的符号链接名称。
        Target  指定新链接引用的路径
                (相对或绝对)。



For instance, if you wanted to make the folder C:\Users\Geek\TestFolder available from C:\TestFolder as well, you could use the following command.
例如,如果你想通过 C:\TestFolder 这个路径访问到 C:\Users\Geek\TestFolder ,你可以使用如下命令:

C:\>mklink /D C:\TestFolder C:\Users\Geek\TestFolder (回车)
symbolic link created for C:\TestFolder <<===>> C:\Users\Geek\TestFolder

在IsaacZ的中文版Win7下显示为:

C:\Users\IsaacZ>mklink /D C:\TestFolder C:\Users\Geek\TestFolder
为 C:\TestFolder <<===>> C:\Users\Geek\TestFolder 创建的符号链接



Now if you look in C:\TestFolder directory, you’ll see whatever files were in the other directory.
现在你打开 C:\TestFolder  目录,会看到 C:\Users\Geek\TestFolder 里的所有内容。


Understanding the Options.
理解各个选项。

MKLINK link target
MKLINK   链接名称  目标文件(夹)名

Using the command without any extra options creates a soft link to a file.
直接使用以上命令,不带任何附加参数,则创建对一个文件的软链接。

/D creates a symbolic link, or a soft link.
/D 参数创建一个符号链接,或者叫软链接。


This essentially acts like a shortcut to a folder in prior versions of Windows, except you don’t have to use an actual shortcut.
这个在本质上作用相当于一个指向文件文件夹的快捷方式,像以前的Windows一样。只是有一点不同:你不必使用一个真实存在的快捷方式。

/H creates a hard link, which points directly to the file.
/H 创建一个硬链接,直接指向文件。


This option can’t be used for folders directly for some reason, you’ll have to use the next option.
这个选项因为某种原因不能直接用于对文件夹的链接。要达到链接文件夹的目的,必须使用下一个选项。

/J creates a “Directory Junction”
/J 创建一个“目录联接”

A Directory Junction is actually just a hard link to a directory. This is a feature that existed prior to Vista as well. If you are trying to symlink to a directory using a hard link, then you should use this option.
一个“目录联接”实际上就是一个指向文件夹的硬链接。这是在 Vista 之前版本的操作系统就存在的功能。如果你想用硬链接的方式为一个目录创建符号链接,那你应该使用这个选项。


Understanding Hard vs Soft Links
理解硬链接和软链接

Hard Link
硬链接

A hard link directly points to the file, and acts to the operating system as if it is the file itself. You’ll want to use this option the majority of the time if you are trying to fake an application’s directory.
一个硬链接直接指向文件,对操作系统来说,仿佛这个硬链接就是被目标文件本身。如果你想伪装一个应用程序文件夹的路径,大多时候会想到用这个选项。

Soft Link
软链接

A soft link is essentially a shortcut to a file or folder – if you are using Windows explorer, you’ll be redirected to the directory if you double-click on a shortcut, it won’t pretend its part of the filesystem. You can still directly reference or open a file with the symlinked path, and it mostly works.
一个软链接本质上是指向一个文件或文件夹的快捷方式——如果你使用Windows资源管理器,当你双击一个快捷方式时,会被转向到它实际指向的文件夹,并不会伪装成文件系统的一部分。尽管如此,你仍然可以通过符号链接路径直接引用或打开一个文件,且大部分情况下都会生效。


Using Symlinks from a Network Share
从网络共享位置使用符号链接

One of the things that’s been extensively discussed is that you cannot use the Vista symlinks from another operating system (not surprising), but you cannot use them from a network share either. This is troublesome if you expect to use this feature on a web server or a file server.
一个广泛讨论的问题是你不能从另外一个操作系统使用Vista的符号链接(这不奇怪),你也不能从一个网络共享位置使用它。如果你想在一个web服务器或文件服务器上使用这个功能,这一点比较烦人。

Deleting Symlinks
删除符号链接

To delete a symlink, you can just delete the link. Just make sure you don’t delete the original file.
要删除符号链接,你只需要删除创建的链接文件就可以了。确保别删除了原始文件就好。



此文是针对Vista的,现在流行WIN7,可能有些功能已经更新。关于这个 mklink 的应用以及软链接和硬链接的详解,请参考IsaacZ后续发布的文章。

第一参考:
[教程] Windows / Linux 下的符号链接完全指南【Symbolic Links (symlinks) 】
IsaacZ的发言中如果提到任何字母缩写或专有名词,在本论坛中一般都能搜索到。点此立即搜索点拨论坛。如有搜索不到的,请尝试搜索百度百科,或者跟帖提问。
发帖前请注意看置顶帖。如果你发现自己的问题没有得到回答,说明你的问题提错了地方或者提问前未先阅读本版规则固顶帖011号
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|点拨论坛

GMT+8, 2024-4-27 22:19 , Processed in 0.176517 second(s), 6 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表