找回密码
 立即注册

QQ登录

只需一步,快速开始

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

[教程] Windows / Linux 下的符号链接完全指南【Symbolic Links (symlinks) 】

[复制链接]

9333

威望

818

金钱

1万

贡献

管理员

自由的灵魂

积分
100458
主题
5590
回帖
26310
注册时间
2003-4-10
最后登录
2024-11-21
发表于 2010-8-5 00:31:40 | 显示全部楼层 |阅读模式

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

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

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

英文原版网页:http://www.howtogeek.com/howto/16226/complete-guide-to-symbolic-links-symlinks-on-windows-or-linux/



Complete Guide to Symbolic Links (symlinks) on Windows or Linux
Windows / Linux 下的符号链接完全指南


翻译 by:IsaacZ  欢迎指正!


Want to easily access folders and files from different folders without maintaining duplicate copies?  Here’s how you can use Symbolic Links to link anything in Windows 7, Vista, XP, and Ubuntu.
想从一个文件夹位置访问另一个位置的文件夹或文件而又不必制作重复的副本吗?这里教给你在 Windows 7, Vista, XP, 和 Ubuntu 下使用符号链接链接另外的文件(夹)的方法。


b8aec34b03729aff37de4f97318a3bd6.png

So What Are Symbolic Links Anyway?
那么究竟什么是符号链接呢?

Symbolic links, otherwise known as symlinks, are basically advanced shortcuts. You can create symbolic links to individual files or folders, and then these will appear like they are stored in the folder with the symbolic link even though the symbolic link only points to their real location.
符号链接的英文是 Symbolic links,简写为 symlinks,简单说是一种高级的快捷方式。你可以创建指向单个文件或文件夹的符号链接,结果这个符号链接看起来就像是一个真实存在的文件夹一样,储存着和目录文件夹一样的文件。

There are two types of symbolic links: hard and soft. Soft symbolic links work essentially the same as a standard shortcut.  When you open a soft link, you will be redirected to the folder where the files are stored.  However, a hard link makes it appear as though the file or folder actually exists at the location of the symbolic link, and your applications won’t know any different. Thus, hard links are of the most interest in this article.
一共有两种类型的符号链接:硬链接和软链接。软链接本质上相当于一个标准的快捷方式。当你打开一个软链接,系统会将当前路径转向到文件的实际存储位置。然而一个硬链接却并不转向,而是本身表现为一个真实的文件或文件夹,好像文件就存储在硬链接所在的位置,并且一般的应用软件根本感知不到中间的差别。因此,硬链接是这篇文章最吸引人之处。

Why should I use Symbolic Links?
为什么要使用符号链接呢?

There are many things we use symbolic links for, so here’s some of the top uses we can think of:
我们可以用符号链接来做很多事情,下面是我们能想到的最典型的应用:
  • Sync any folder with Dropbox – say, sync your Pidgin Profile Across Computers
    通过 Dropbox 同步任意文件夹,比如说,在计算机间同步你的 Pidgin 配置文件
  • Move the settings folder for any program from its original location
    将任意程序的设置文件夹从原始位置移动到别处
  • Store your Music/Pictures/Videos on a second hard drive, but make them show up in your standard Music/Pictures/Videos folders so they’ll be detected by your media programs (Windows 7 Libraries can also be good for this)
    将你的音乐、图片、视频等存放于另一块硬盘上,却让它们显示在“音乐”、“图片”、“视频”等系统分配的标准文件夹当中,以便可以被媒体程序直接侦测到。(WIN7 的“库”也同样可以这样用)
  • Keep important files accessible from multiple locations
    让比较重要的文件显示在多处位置,以便可以快速访问
  • And more!
    更多用处有待你去发现哦~~


If you want to move files to a different drive or folder and then symbolically link them, follow these steps:
如果你想将文件移动到另一个驱动器或文件夹,然后用符号链接指向它们,请按如下步骤操作:
  • Close any programs that may be accessing that file or folder
    关闭任何可能使用这些文件的程序
  • Move the file or folder to the new desired location
    移动相关文件或文件夹到中意的位置
  • Follow the correct instructions below for your operating system to create the symbolic link.
    按照下面的说明,根据不同的操作系统类型来创建符号链接。



Caution: Make sure to never create a symbolic link inside of a symbolic link. For instance, don’t create a symbolic link to a file that’s contained in a symbolic linked folder. This can create a loop, which can cause millions of problems you don’t want to deal with. Seriously.
警告:永远不要在一个符号链接内部创建符号链接!例如,不要为一个存在于某符号链接文件夹内的文件创建符号链接。这将导致循环,产生你不愿面对的N种问题!


Create Symlinks in Any Edition of Windows in Explorer
在任意Windows版本中通过资源管理器创建符号链接

Creating symlinks is usually difficult, but thanks to the free Link Shell Extension, you can create symbolic links in all modern version of Windows pain-free.  You need to download both Visual Studio 2005 redistributable, which contains the necessary prerequisites, and Link Shell Extension itself (links below).  Download the correct version (32 bit or 64 bit) for your computer.

Download Link Shell Extension for Windows 7, Vista, and XP

Run and install the Visual Studio 2005 Redistributable installer first.
6d54764f977a0887bf7e5ea776be73ea.png
Then install the Link Shell Extension on your computer. Your taskbar will temporally disappear during the install, but will quickly come back.
7ac51418751893e69fb394c0e2045c09.png
Now you’re ready to start creating symbolic links.  Browse to the folder or file you want to create a symbolic link from.  Right-click the folder or file and select Pick Link Source.
7f99affc8926f72090077c0833db579d.png
To create your symlink, right-click in the folder you wish to save the symbolic link, select “Drop as…”, and then choose the type of link you want.  You can choose from several different options here; we chose the Hardlink Clone.  This will create a hard link to the file or folder we selected.  The Symbolic link option creates a soft link, while the smart copy will fully copy a folder containing symbolic links without breaking them.  These options can be useful as well.
519a6da69f21764ab19e94174abb402a.png
Here’s our hard-linked folder on our desktop.  Notice that the folder looks like its contents are stored in Desktop\Downloads, when they are actually stored in C:\Users\Matthew\Desktop\Downloads.  Also, when links are created with the Link Shell Extension, they have a red arrow on them so you can still differentiate them.
bd7afb7364d5aa9c79de65e76876fec4.png
And, this works the same way in XP as well.
3915b02a3c6823ac450249caac3843af.png
IsaacZ的发言中如果提到任何字母缩写或专有名词,在本论坛中一般都能搜索到。点此立即搜索点拨论坛。如有搜索不到的,请尝试搜索百度百科,或者跟帖提问。
发帖前请注意看置顶帖。如果你发现自己的问题没有得到回答,说明你的问题提错了地方或者提问前未先阅读版规。

9333

威望

818

金钱

1万

贡献

管理员

自由的灵魂

积分
100458
主题
5590
回帖
26310
注册时间
2003-4-10
最后登录
2024-11-21
 楼主| 发表于 2010-8-5 00:33:50 | 显示全部楼层
本帖最后由 IsaacZ 于 2010-8-5 00:36 编辑

Symlinks via Command Prompt
Or, for geeks who prefer working via command line, here’s how you can create symlinks in Command Prompt in Windows 7/Vista and XP.
In Windows 7/Vista
In Windows Vista and 7, we’ll use the mklink command to create symbolic links.  To use it, we have to open an administrator Command Prompt.  Enter “command” in your start menu search, right-click on Command Prompt, and select “Run as administrator”.
410d78cdff56492442ceb2626df64dd1.png
To create a symbolic link, we need to enter the following in command prompt:

mklink /prefix link_path file/folder_path

First, choose the correct prefix.  Mklink can create several types of links, including the following:
  • /D – creates a soft symbolic link, which is similar to a standard folder or file shortcut in Windows.  This is the default option, and mklink will use it if you do not enter a prefix.
  • /H – creates a hard link to a file
  • /J – creates a hard link to a directory or folder

So, once you’ve chosen the correct prefix, you need to enter the path you want for the symbolic link, and the path to the original file or folder.  For example, if I wanted a folder in my Dropbox folder to appear like it was also stored in my desktop, I would enter the following:

mklink /J C:\Users\Matthew\Desktop\Dropbox C:\Users\Matthew\Documents\Dropbox

Note that the first path was to the symbolic folder I wanted to create, while the second path was to the real folder.
Here, in this command prompt screenshot, you can see that I created a symbolic link of my Music folder to my desktop.
daaff22d604b185a01244939b8571135.png
And here’s how it looks in Explorer.  Note that all of my music is “really” stored in C:\Users\Matthew\Music, but here it looks like it is stored in C:\Users\Matthew\Desktop\Music.
e046c946742565f61625bf47200afcc6.png
If your path has any spaces in it, you need to place quotes around it.  Note also that the link can have a different name than the file it links to.  For example, here I’m going to create a symbolic link to a document on my desktop:

mklink /H “C:\Users\Matthew\Desktop\ebook.pdf”  “C:\Users\Matthew\Downloads\Before You Call Tech Support.pdf”

Don’t forget the syntax:

mklink /prefix link_path Target_file/folder_path


In Windows XP

Windows XP doesn’t include built-in command prompt support for symbolic links, but we can use the free Junction tool instead.  Download Junction for XP, and unzip the folder.  Now open Command Prompt (click Start, select All Programs, then Accessories, and select Command Prompt), and enter cd followed by the path of the folder where you saved Junction.

2b096696d9e1b6799eb4ecdef7d7ce72.png

Junction only creates hard symbolic links, since you can use shortcuts for soft ones.  To create a hard symlink, we need to enter the following in command prompt:

junction –s link_path file/folder_path

As with mklink in Windows 7 or Vista, if your file/folder path has spaces in it make sure to put quotes around your paths.  Also, as usual, your symlink can have a different name that the file/folder it points to.
Here, we’re going to create a symbolic link to our My Music folder on the desktop.  We entered:

junction -s “C:\Documents and Settings\Administrator\Desktop\Music” “C:\Documents and Settings\Administrator\My Documents\My Music”

52f26a1f0cfd4c5e4f51da4a4ce512ad.png
And here’s the contents of our symlink.  Note that the path looks like these files are stored in a Music folder directly on the Desktop, when they are actually stored in My Documents\My Music.  Once again, this works with both folders and individual files.
452152215be94d77bfc8d4a27147c497.png
Please Note: Junction would work the same in Windows 7 or Vista, but since they include a built-in symbolic link tool we found it better to use it on those versions of Windows.
IsaacZ的发言中如果提到任何字母缩写或专有名词,在本论坛中一般都能搜索到。点此立即搜索点拨论坛。如有搜索不到的,请尝试搜索百度百科,或者跟帖提问。
发帖前请注意看置顶帖。如果你发现自己的问题没有得到回答,说明你的问题提错了地方或者提问前未先阅读版规。
回复

使用道具 举报

9333

威望

818

金钱

1万

贡献

管理员

自由的灵魂

积分
100458
主题
5590
回帖
26310
注册时间
2003-4-10
最后登录
2024-11-21
 楼主| 发表于 2010-8-5 00:34:31 | 显示全部楼层
Symlinks in Ubuntu

Unix-based operating systems have supported symbolic links since their inception, so it is straightforward to create symbolic links in Linux distros such as Ubuntu.  There’s no graphical way to create them like the Link Shell Extension for Windows, so we’ll just do it in Terminal.
Open terminal (open the Applications menu, select Accessories, and then click Terminal), and enter the following:

ln –s file/folder_path link_path

Note that this is opposite of the Windows commands; you put the source for the link first, and then the path second.
For example, let’s create a symbolic link of our Pictures folder in our Desktop.  To do this, we entered:

ln -s /home/maguay/Pictures /home/maguay/Desktop

f52c29e1476ec45d7b4de19d63c4b2ce.png
Once again, here is the contents of our symlink folder.  The pictures look as if they’re stored directly in a Pictures folder on the Desktop, but they are actually stored in maguay\Pictures.
fd92ccac02d0941feb15886fd4982dee.png
IsaacZ的发言中如果提到任何字母缩写或专有名词,在本论坛中一般都能搜索到。点此立即搜索点拨论坛。如有搜索不到的,请尝试搜索百度百科,或者跟帖提问。
发帖前请注意看置顶帖。如果你发现自己的问题没有得到回答,说明你的问题提错了地方或者提问前未先阅读版规。
回复

使用道具 举报

9333

威望

818

金钱

1万

贡献

管理员

自由的灵魂

积分
100458
主题
5590
回帖
26310
注册时间
2003-4-10
最后登录
2024-11-21
 楼主| 发表于 2010-8-5 00:37:03 | 显示全部楼层
Delete Symlinks

Removing symbolic links is very simple – just delete the link!  Most of the command line utilities offer a way to delete a symbolic link via command prompt, but you don’t need to go to the trouble.
f5f7ddbe48849f0d85b03bb2a514a087.png


Conclusion
Symbolic links can be very handy, and we use them constantly to help us stay organized and keep our hard drives from overflowing.  Let us know how you use symbolic links on your computers!

Download Link Shell Extension for Windows 7, Vista, and XP
Download Junction for XP


[url=]
[/url][url=]
[/url][url=]
[/url]|
More



This article was originally written on 05/4/10
IsaacZ的发言中如果提到任何字母缩写或专有名词,在本论坛中一般都能搜索到。点此立即搜索点拨论坛。如有搜索不到的,请尝试搜索百度百科,或者跟帖提问。
发帖前请注意看置顶帖。如果你发现自己的问题没有得到回答,说明你的问题提错了地方或者提问前未先阅读版规。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|点拨论坛 |网站地图

GMT+8, 2024-11-21 21:43 , Processed in 0.253656 second(s), 6 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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