如何使用 New-Hardlink PowerShell PSCX 命令创建硬链接

发布于 2024-08-02 04:56:56 字数 870 浏览 8 评论 0原文

我想使用 PowerShell 社区扩展 PSCX commandlet New-Hardlink http://pscx.codeplex.com/ 创建新的硬链接。我已经阅读了 man 文件并尝试了几乎所有命令组合,但它不起作用。我缺少什么? (我知道 fsutil,但我想使用这个命令行开关/别名)

这是目录结构: E:\来源 E:\Test

以下是我尝试过的命令的一些变体:

New-Hardlink E:\Test\Source E:\Source
New-Hardlink -Path:"E:\Test\Source" -Target:"E:\Source"
New-Hardlink E:\Source E:\Test\Source
New-Hardlink E:\Source E:\Test\
New-Hardlink -P:"E:\Source" -T:"E:\Test\Source"

这是假定的语法:

New-Hardlink [-Path] <String> [-Target] <String> [<CommonParameters>]

-Path <String>
    Path to the new link.

-Target <String>
    Target of the link.

结果总是来自以下内容:

New-Hardlink : Unable to find the file 'E:\Source.

此命令不适用于目录,而仅适用于文件吗?

I want to create a new Hardlink with the PowerShell Community Extensions PSCX commandlet New-Hardlink http://pscx.codeplex.com/. I have read the man file and tried almost every combination of commands but it won't work. What am I missing? (I know about fsutil, but I want to use this commandlet/alias)

Here is the directory structure:
E:\Source
E:\Test

Here are some variations of the command that I have tried:

New-Hardlink E:\Test\Source E:\Source
New-Hardlink -Path:"E:\Test\Source" -Target:"E:\Source"
New-Hardlink E:\Source E:\Test\Source
New-Hardlink E:\Source E:\Test\
New-Hardlink -P:"E:\Source" -T:"E:\Test\Source"

Here is the supposed syntax:

New-Hardlink [-Path] <String> [-Target] <String> [<CommonParameters>]

-Path <String>
    Path to the new link.

-Target <String>
    Target of the link.

The result is always some from of:

New-Hardlink : Unable to find the file 'E:\Source.

Does this command not work with directories but only with files?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

卷耳 2024-08-09 04:56:56

我会羞涩地回答我自己的问题。

是的,硬链接确实是指文件。要通过目录完成此操作,应像这样使用 New-Junction 命令:

New-Junction E:\Test\Dest E:\Source

第一个参数指您要放置新 Junction 的位置。

第二个参数是指你要Junction的目录

I will sheepishly answer my own question.

Yes, indeed Hardlinks refer to files. To accomplish this with directories the New-Junction command should be used like so:

New-Junction E:\Test\Dest E:\Source

The first parameter refers to the location you would like to place the new Junction.

The second parameter refers to the directory you wish to Junction

还给你自由 2024-08-09 04:56:56

Powershell 5+ 包含创建任何类型的硬/软链接和联结的本机方法。

对于来自 Google 的用户:

PowerShell 5.0 及更高版本支持使用 New-Item cmdlet。

在下面,点击 B.txt 将转到 A.txt。对于目录也是如此。

# To create a symbolic link on a file:
New-Item -ItemType SymbolicLink -Name B.txt -Target A.txt
New-Item -ItemType SymbolicLink -Path C:\Temp\B.txt -Value A.txt

# To create a hard-link on a file:
New-Item -ItemType HardLink -Path C:\B.txt -Value C:\A.txt

# To create a symbolic link on a directory:
New-Item -ItemType SymbolicLink -Name B_Directory -Target C:\A_Directory

# To create a junction on a directory:
New-Item -ItemType Junction -Path C:\Junction -Value C:\A_Directory

Powershell 5+ include a native way to create any types of hard-/soft-links and junctions.

For those coming from Google:

PowerShell 5.0 and above have support for creating Symbolic Links and Junctions using the New-Item cmdlet.

In the following, clicking on B.txt will take you to A.txt. Similarly for a directory.

# To create a symbolic link on a file:
New-Item -ItemType SymbolicLink -Name B.txt -Target A.txt
New-Item -ItemType SymbolicLink -Path C:\Temp\B.txt -Value A.txt

# To create a hard-link on a file:
New-Item -ItemType HardLink -Path C:\B.txt -Value C:\A.txt

# To create a symbolic link on a directory:
New-Item -ItemType SymbolicLink -Name B_Directory -Target C:\A_Directory

# To create a junction on a directory:
New-Item -ItemType Junction -Path C:\Junction -Value C:\A_Directory
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文