Windows 有 ln -s 或等效的吗?

pro*_*eek 42 windows symbolic-link

我需要将文件链接到 C:\Windows\System32\drivers\etc\hosts

我怎么能用 Windows 做到这一点?ln -sWindows 中是否有诸如或等效的软链接?

sci*_*gor 44

您正在寻找命令“mklink”。

Microsoft Docsss64.com 中的文档和示例。

来自链接的示例:

// To create a symbolic link named MyDocs from the root directory to the \Users\User1\Documents directory, type:
mklink /d \MyDocs \Users\User1\Documents
Run Code Online (Sandbox Code Playgroud)

  • 请注意,您需要管理员权限才能创建符号链接。 (5认同)

小智 17

可能还有其他方法,但我熟悉的方法是 mklink:

C:\>mklink 
Creates a symbolic link.

MKLINK [[/D] | [/H] | [/J]] Link Target

        /D      Creates a directory symbolic link.  Default is a file
                symbolic link.
        /H      Creates a hard link instead of a symbolic link.
        /J      Creates a Directory Junction.
        Link    specifies the new symbolic link name.
        Target  specifies the path (relative or absolute) that the new link
                refers to.
Run Code Online (Sandbox Code Playgroud)


mao*_*izm 9

电源外壳

只要微软从 5 多年前就建议使用cmd.exe作为命令解释器,并且正在成为遗留应用程序,这个问题在 Powershell 中就缺乏答案:

New-Item -path ~\Desktop\hosts -itemType SymbolicLink -target c:\Windows\System32\Drivers\etc\hosts
Run Code Online (Sandbox Code Playgroud)

这适用于 Powershell v5.0