mklink 未安装在 Windows 7 上?

Pau*_*han 43 windows-7

我刚刚安装了 Windows 7 专业版,我正在根据自己的喜好对其进行配置。我去设置一个符号链接(因为它支持符号链接)。

但是我好像没有这个mklink程序C:\Windows\system32

在 Powershell 的管理员模式下:

PS C:\> mklink
The term 'mklink' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spel
ling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:7
+ mklink <<<<
    + CategoryInfo          : ObjectNotFound: (mklink:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
Run Code Online (Sandbox Code Playgroud)

use*_*686 61

mklink不是一个独立的工具——它是 Cmd.exe 解释器中的一个内置命令。在外部运行它的唯一方法是通过cmd /c(类似于sh -c在 Linux 上):

cmd /c mklink参数

但是,PowerShell 本身支持使用cmdlet创建各种链接类型New-Item,尽管它不是一个完整的替代品(因为它不支持创建相对符号链接)。

New-Item -ItemType SymbolicLink|Junction|HardLink -Name Foo -Target Bar

  • 这也适用于 Windows 10 专业版 (2认同)
  • `alias mklink='cmd //c mklink'` 用于 Git Bash;/sf/answers/1533511101/ (2认同)

Pau*_*han 15

解决方案是 mklink 是 cmd.exe 的内置程序。因此,Powershell 无法直接访问它。

对想到这一点的人的负面荣誉。


小智 8

PowerShell 并不是 CMD 的完全替代品。许多 CMD 功能在 PS 中不起作用。切换到 CMD 运行 mklink