活力37907
在线时间12212 小时
阅读权限200
管理员
自由的灵魂
- 积分
- 100571
- 主题
- 5293
- 回帖
- 26240
- 注册时间
- 2003-4-10
- 最后登录
- 2024-12-22
|
楼主 |
发表于 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”.
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.
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.
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.
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”
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.
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. |
|