[转载声明] 转载时必须标注:本文来源于铁木箱子的博客http://www.mzone.cc
[本文地址] 本文永久地址是: http://www.mzone.cc/article/619.html

用过Linux的朋友都知道linux中有软链接的概念,可以通过ln命令创建到目录或文件的软链接,软链接的好处就是可以让一个目录或文件有多个入口但保持单一物理位置,方便应用和管理。在Linux下创建软链接一般用如下命令:

<ol style="padding: 0px; margin: 0px;"><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;"># ln -sf file1 file2</div></li><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;"> </div></li><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;">其中file1是软件链接的名称,file2是实际文件的路径,以后通过file1就可以访问file2了</div></li></ol>

之前一直苦于windows下没有类似的功能,导致有些地方很不方便,不过进入windows vista和win7时代后,这样的功能也被附带在windows中了,通过win7操作系统中的mklink命令就可以创建类似的软链接了。

<ol style="padding: 0px; margin: 0px;"><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;">D:\temp<span style="color: rgb(0, 0, 0); "><strong>></strong></span>mklink <span style="color: rgb(0, 0, 0); "><strong>/</strong></span>?</div></li><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;">创建符号链接。</div></li><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;"> </div></li><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;">MKLINK <span style="font-weight: bold;">[</span><span style="font-weight: bold;">[</span><span style="color: rgb(0, 0, 0); "><strong>/</strong></span>D<span style="font-weight: bold;">]</span> <span style="color: rgb(0, 0, 0); "><strong>|</strong></span> <span style="font-weight: bold;">[</span><span style="color: rgb(0, 0, 0); "><strong>/</strong></span>H<span style="font-weight: bold;">]</span> <span style="color: rgb(0, 0, 0); "><strong>|</strong></span> <span style="font-weight: bold;">[</span><span style="color: rgb(0, 0, 0); "><strong>/</strong></span>J<span style="font-weight: bold;">]</span><span style="font-weight: bold;">]</span> Link Target</div></li><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;"> </div></li><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;">        <span style="color: rgb(0, 0, 0); "><strong>/</strong></span>D      创建目录符号链接。默认为文件</div></li><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;">                符号链接。</div></li><li style="list-style-type: none; vertical-align: top; font-weight: bold;"><div style="padding: 0px; margin: 0px; font-weight: normal; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;">        <span style="color: rgb(0, 0, 0); "><strong>/</strong></span>H      创建硬链接,而不是符号链接。</div></li><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;">        <span style="color: rgb(0, 0, 0); "><strong>/</strong></span>J      创建目录联接。</div></li><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;">        Link    指定新的符号链接名称。</div></li><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;">        Target  指定新链接引用的路径</div></li><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;">                <span style="font-weight: bold;">(</span>相对或绝对<span style="font-weight: bold;">)</span>。</div></li></ol>

上面的是mklink命令的帮助信息,可以看到mklink可以创建目录和文件链接。比如D:\temp目录下有目录dir1,我想在当前目录下创建到dir1目录的软链接,可以使用如下命令来操作:

<ol style="padding: 0px; margin: 0px;"><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;">mklink <span style="color: rgb(0, 0, 0); "><strong>/</strong></span>D dir2 dir1</div></li><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;">mklink <span style="color: rgb(0, 0, 0); "><strong>/</strong></span>J dir3 dir1</div></li></ol>

上面两个命令都可以实现到dir1的软链接,参数/D和/J是创建目录软链接必须的,目前来说着两个参数都可以实现目录软链接,而且应用过程中也没有发现有什么区别的地方,唯一的区别就是dir2和dir3链接的类型不懂,可以通过dir命令查看得到结果如下:

<ol style="padding: 0px; margin: 0px;"><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;"><span style="color: rgb(0, 0, 0);">2011</span><span style="color: rgb(0, 0, 0); "><strong>/</strong></span>05<span style="color: rgb(0, 0, 0); "><strong>/</strong></span><span style="color: rgb(0, 0, 0);">17</span>  <span style="color: rgb(0, 0, 0);">14</span>:05    <span style="color: rgb(0, 0, 0); "><strong><</strong></span>DIR<span style="color: rgb(0, 0, 0); "><strong>></strong></span>          dir1</div></li><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;"><span style="color: rgb(0, 0, 0);">2011</span><span style="color: rgb(0, 0, 0); "><strong>/</strong></span>05<span style="color: rgb(0, 0, 0); "><strong>/</strong></span><span style="color: rgb(0, 0, 0);">24</span>  <span style="color: rgb(0, 0, 0);">13</span>:07    <span style="color: rgb(0, 0, 0); "><strong><</strong></span>JUNCTION<span style="color: rgb(0, 0, 0); "><strong>></strong></span>     dir2 <span style="font-weight: bold;">[</span>D:\temp\dir1<span style="font-weight: bold;">]</span></div></li><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;"><span style="color: rgb(0, 0, 0);">2011</span><span style="color: rgb(0, 0, 0); "><strong>/</strong></span>05<span style="color: rgb(0, 0, 0); "><strong>/</strong></span><span style="color: rgb(0, 0, 0);">24</span>  <span style="color: rgb(0, 0, 0);">13</span>:07    <span style="color: rgb(0, 0, 0); "><strong><</strong></span>SYMLINKD<span style="color: rgb(0, 0, 0); "><strong>></strong></span>     dir3 <span style="font-weight: bold;">[</span>dir1<span style="font-weight: bold;">]</span></div></li></ol>

我们可以发现dir1是DIR类型(这个是我们创建的实际目录),dir2是JUNCTION类型,而dir3是SYMLINKD类型,这个或许是区别,但应用中效果一样。

说完了目录软链接,文件当然也可以创建软链接了,而且还可以创建硬连接,比如d:\temp目录下有abc.txt文件,我要创建到这个文件的软链接的命令如下:

<ol style="padding: 0px; margin: 0px;"><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;">mklink abc1.txt abc.txt</div></li></ol>

这样我们就创建了一个到abc.txt文件的软链接abc1.txt,对于文件还可以创建硬链接,硬链接个人感觉用处不大,因为创建硬链接是磁盘上空间是增加了双倍,对于硬链接而言,修改硬链接文件和原始文件的内容都会相互影响,即内容是一致的但空间占用确是双份的。使用如下命令创建硬链接:

<ol style="padding: 0px; margin: 0px;"><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;">mklink <span style="color: rgb(0, 0, 0); "><strong>/</strong></span>H abc2.txt abc.txt</div></li></ol>

文件的软链接和硬链接的类型查看如下(用dir命令):

<ol style="padding: 0px; margin: 0px;"><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;"><span style="color: rgb(0, 0, 0);">2011</span><span style="color: rgb(0, 0, 0); "><strong>/</strong></span>05<span style="color: rgb(0, 0, 0); "><strong>/</strong></span><span style="color: rgb(0, 0, 0);">24</span>  <span style="color: rgb(0, 0, 0);">13</span>:<span style="color: rgb(0, 0, 0);">33</span>                 <span style="color: rgb(0, 0, 0);">7</span> abc.txt</div></li><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;"><span style="color: rgb(0, 0, 0);">2011</span><span style="color: rgb(0, 0, 0); "><strong>/</strong></span>05<span style="color: rgb(0, 0, 0); "><strong>/</strong></span><span style="color: rgb(0, 0, 0);">24</span>  <span style="color: rgb(0, 0, 0);">13</span>:<span style="color: rgb(0, 0, 0);">30</span>    <span style="color: rgb(0, 0, 0); "><strong><</strong></span>SYMLINK<span style="color: rgb(0, 0, 0); "><strong>></strong></span>      abc1.txt <span style="font-weight: bold;">[</span>abc.txt<span style="font-weight: bold;">]</span></div></li><li style="list-style-type: none; vertical-align: top;"><div style="padding: 0px; margin: 0px; font-stretch: normal; font-size: 1em; line-height: 1.2em; vertical-align: top;"><span style="color: rgb(0, 0, 0);">2011</span><span style="color: rgb(0, 0, 0); "><strong>/</strong></span>05<span style="color: rgb(0, 0, 0); "><strong>/</strong></span><span style="color: rgb(0, 0, 0);">24</span>  <span style="color: rgb(0, 0, 0);">13</span>:<span style="color: rgb(0, 0, 0);">33</span>                 <span style="color: rgb(0, 0, 0);">7</span> abc2.txt</div></li></ol>

发现硬链接和普通的文件没有什么区别,唯一的区别就是修改的内容会直接影响到原始文件。

基本上win7系统下软链接创建和基本知识就介绍到这里,对这些有什么用处,举个例子,我们常见的在windows下开发PHP程序,而php程序又需要在apache下运行,一般情况下我们需要修改apache的htdocs目录或者把代码放到htdocs目录下才可以运行。但是用了软链接后,我们可以在apache的htdcos目录下创建一个到目录软链接到实际开发目录,这样我们代码开发就可以直接在apache中进行预览更新了,当然你也可以用这个技术在其他任何想要的地方。

顺带补充一句,软链接的目录和文件都可以直接删除,不会影响到原始目录和文件的,这个也非常方便,而且软链接的目录和文件图标上都有一个小箭头,很好区分。

mklink命令相关文章: http://www.cnblogs.com/asion/archive/2011/03/10/1979282.html

Win7中的软链接详解(mklink命令)相关推荐

  1. python3中argparse模块详解

    文章目录 python3中argparse模块详解 一. 命令行参数分为位置参数和选项参数: 二. 使用步骤: 三. add_argument()方法参数: 1. name or flags: 2. ...

  2. linux命令 正则表达式,详解Linux命令中的正则表达式

    详解Linux命令中的正则表达式 Mark Do 2017年9月19日 暂无评论 阅读 981 次 命令中的正则表达式 如果要在命令输出或文本中筛选内容时使用模糊查找,就需要使用正则表达式.正则表达式 ...

  3. linux 的文件软链接隐藏,Linux inode及硬链接软链接详解

    Linux inode及硬链接软链接详解 York • 2020 年 09 月 28 日 Loading... 操作系统的文件数据除了实际内容之外,通常含有非常多的属性,例如 `Linux`操作系统的 ...

  4. ARP命令详解--网络命令详解二

    显示和修改"地址解析协议 (ARP)"缓存中的项目.ARP 缓存中包含一个或多个表,它们用于存储 IP 地址及其经过解析的以太网或令牌环物理地址.计算机上安装的每一个以太网或令牌环 ...

  5. Cocos2d-x win7 + vs2010 配置图文详解(亲测)

    Cocos2d-x win7 + vs2010 配置图文详解(亲测) 下载最新版的cocos2d-x.打开浏览器,输入cocos2d-x.org,然后选择Download,本教程写作时最新版本为coc ...

  6. Linux中etc目录详解

    Linux中etc目录详解 /etc目录 包含很多文件.许多网络配置文件也在/etc 中. /etc/rc   or/etc/rc.d   or/etc/rc*.d   启动.或改变运行级时运行的sc ...

  7. Matlab中 pdist 函数详解

    学习笔记,仅供参考,有错必纠 转载自:Matlab中 pdist 函数详解(各种距离的生成); pdist Pairwise distance between pairs of objects. Sy ...

  8. mysql increment_mysql中auto_increment用法详解

    在mysql中AUTO_INCREMENT类型的属性用于为一个表中记录自动生成ID功能,也就是会自动自增一个ID了,如现在是1下次会自动是2了,就这么简单,下面来看mysql中auto_increme ...

  9. 批处理中的for详解

    批处理中的for详解 简单说,FOR是个循环,可以用你指定的循环范围生成一系列命令.最简单的例子,就是人工指定循环范围,然后对每个值执行指定的命令.例如,想快速报告每个硬盘分区的剩余空间: for % ...

最新文章

  1. java过滤4字节_乐字节Java8核心特性实战之四:方法引用
  2. 台式计算机不用待机还是关机好,电脑应该选择“关机”还是“休眠”?不关机对电脑有损伤吗?...
  3. 逆向工程核心原理学习笔记(七):总结
  4. 华硕vm510l拆电池图解_图解说设备:凯斯CX80C你会买吗?
  5. java学习(41):成员实例的定义和访问续
  6. NOI数据结构:主席树
  7. (30)System Verilog设计SPI发送
  8. UTF-8 和 Unicode 的区别
  9. load data(sql)
  10. JavaSE11: 简单快速掌握枚举
  11. 早上收到这样一份通知,求一无漏洞框架,无力吐槽
  12. [原创] 对于深度学习(deep learning)在工业界的应用现状和突破 [by matthewbai]
  13. ASP.NET Core部署在IIS上
  14. Android 判定手机是否root
  15. 新宝线上股票大箱体终于向上突破站稳了
  16. shell中各种括号用法
  17. CDOJ 1131 男神的礼物 区间dp
  18. 解析P2P金融的业务安全
  19. LR推导及其与SVM的区别
  20. Android让屏幕保持常亮,不熄屏的三种方法

热门文章

  1. 没分啊,下载不了东西苦逼啊~!
  2. K12866 班级合并
  3. vi新建一个shell脚本_如何在Vim中为Shell脚本创建自定义页眉模板
  4. python语言中不属于组合数据类型的是_下列不属于组合数据类型的是()。
  5. java梭哈的小游戏
  6. zzuli 1131
  7. HTML5 Canvas 学习之一
  8. 又输了,OpenAI Five完胜Dota 2半职业战队
  9. 【Leetcode刷题】:Python:416. 分割等和子集
  10. 串口和以太网口的区别