zoukankan      html  css  js  c++  java
  • mklink让网盘同步不同文件夹

    mklink简介

    Linux 下有一个叫符号链接的东东,是 ln 这个链接命令,mklink 和 ln 的功能几乎一样。在xp系统下,junction命令要用微软开发的小程序 junction.exe实现,从http://live.sysinternals.com/可以下载。现在Windows Vista之后的系统自带了mklink的功能。创建符号链接不仅可以当作快捷方式使用,最重要的是重定向链接符可以被程序读取然后重定向真正的位置,这是快捷方式无法做到的。

    win+r -> cmd -> mklink:

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

    默认情况:

    • 文件的符号链接,如没有参数指定,则创建文件的符号链接,删除文件链接不会影响目 标文件,且创建链接时允许目标文件不存在;
    • 目录的符号链接(SYMLINKD) /D该参数可以创建目录的符号链接,删除目录链接不 会影响目标目录,且创建链接时允许目标目录不存在;
    • 目录的软链接(JUNCTION) /J 该参数可以创建目录的软链接(联接),作用基本和符号链接类似,NT6系统的用户目录就是以这种形式存在的;
    • 文件的硬链接 /H 该参数可以创建文件的硬链接,即一个文件的多个别名,NT6系统WinSXS目录下的大部分文件是以这个形式存在的;

    mklink的应用

    根据上面的介绍大家肯定知道我想干什么了,对!就是利用mklink为网盘加上多目录同步的功能。下面以Dropbox备份某软件的配置为例,其他的网盘都类似:
    网盘的同步文件夹是E:/u/Dropbox,需要同步的文件夹是D:/soft1/config我们使用下面的命令:

    mklink /D "E:/u/Dropbox/mydata" "D:/soft1/config"

    这样E:/u/Dropbox/mydata就指向D:/mydata,相当于两个访问接口。

    删除E:/u/Dropbox/mydata不会影响到D:/soft1/config,反之则不行。

    按照这种方法就可以让Dropbox等网盘部分不同的文件夹了。

    但是现在也有个问题,你会发现只有Dropbox第一次启动或者重启时会同步,你的修改不能马上被Dropbox捕获到,

    Dropbox可以使用系统托盘菜单中的暂停和恢复同步来手动让Dropbox对修改进行捕获,

    有些网盘如酷盘就没有这个功能,只能利用重启软件来同步,很不方便。

    其实这里还有个方法就是:我们反着来,将真实文件夹(如config)放在Dropbox中,在D:/soft1/中创建软连接, 如命令:

    mklink /D "D:/soft1/config" "E:/u/Dropbox/mydata"

    这样的缺点就是其实根本没有改进网盘不支持多目录备份的问题,而是和系统开玩笑而已,但是这样确实很方便,我目前基本使用这种方法。

    How to remove a symbolic link?

    To delete a symbolic link to a file or directory, the following command line syntax can be used

    (in each case, "linkname" specifies the name of the symbolic link to be deleted):

    • For links to files:
      del linkName
    • For links to directories:
      rmdir linkName  
    If you used mklink or mklink /h 
    to create a symbolic link or hard link to a file,
    then del will delete the link without affecting the target file.
     
    If you used mklink /d or mklink /j 
    to create a symbolic link or junction for a directory,
    then it works like an empty folder.
    You need to use rmdir to remove it. 
    The target directory will be unaffected.
     
    If you instead use del on the link or junction, then it works just like on any other folder:
    you are prompted to confirm whether you want to delete all the directory's files (but not subdirectories).
    The target directory's files will be deleted if you answer "y".
    You can avoid the prompt if you use del /q.
     
    In Explorer, if you delete the link or junction, that's all that will be deleted; 
    the target folder is unaffected. 
     
    This also applies to the Recycle Bin.
    When moving the link or junction, you are prompted to confirm that you want to move the "folder".
    But actually, only the link or junction will be put in the Recycle Bin, not the target folder.
    the target folder is unaffected. 
     
    In any case, if you explicitly delete the target file or folder,
    then any symbolic links or junctions pointing to it will be left behind,
    unusable until the target is recreated.
     
    Any hard links to deleted files, or to files in deleted directories, will be unaffected.
     
    In Powershell, don't use rmdir!
    Use cmd /c rmdir .Target instead.
    I tested this myself and confirmed it here: 
     
     
  • 相关阅读:
    CoreOS Hyper-V 安装
    RancherOS Hyper-V 安装
    Android sdk content loader 0%的解决方案
    在launcher隐藏应用图标[大杂烩]
    RTSP、HTTP、HTTPS、SDP四种协议详解
    Webview上下滑动渐变色问题解决
    调节listview的item高度
    软键盘消失有残影 不影响activity原有布局 不会重绘之前界面
    android横竖屏禁止重新绘制的方法
    去除actionbar的左侧图标
  • 原文地址:https://www.cnblogs.com/shangdawei/p/4516874.html
Copyright © 2011-2022 走看看