Enable native NTFS symbolic links for Cygwin

前端 未结 5 977
长发绾君心
长发绾君心 2020-11-27 12:26

Recent NTFS and Windows implement symlinks:

  • NTFS junction point can be used as directory symlink since NTFS 3.0 (Windows 2000) using linkd or
5条回答
  •  Happy的楠姐
    2020-11-27 12:34

    Since @olibre answer didn't work for me. I just created a shell function.

    : '
    mklink - Create NTFS (Windows) links that is usable by Windows and Cygwin
    
    Usage: mklink [/D | /H | /J]  
    
    Options:
        /D    Directory Symbolic Link
        /H    Hardlink
        /J    Directory Junction (you should prefer /D)
    
    With no options, it creates a NTFS file symlink.
    '
    mklink () {
    
        if [ "$#" -ge "3" ]; then
            cmd /c mklink "$1" "$(cygpath --windows --absolute "$2")" "$(cygpath --windows --absolute "$3")"
        else
            cmd /c mklink "$(cygpath --windows --absolute "$1")" "$(cygpath --windows --absolute "$2")"
        fi
    
    }
    

    Do note you need administrator permissions (for Cygwin) to run the above without problems.

    Note that I am unaware whether there's any difference between symlinking to an absolute path versus symlinking to a relative path using CMD's mklink. On Linux, those 2 have different behaviours if you ever decide to move the symlink or move the target file, or move both.

提交回复
热议问题