当您在命令提示符cmd.exe中使用cmd.exe时,
C:\path\to\somewhere> dir
2022-10-03 20:17 <DIR> .
2022-10-03 19:54 <DIR> ..
2022-10-03 20:16 <SYMLINKD> link [..\target\]但是,当您在PowerShell中尝试同样的方法时,您会得到
PS C:\path\to\somewhere> dir
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----l 2022-10-03 20:16 link如何使PowerShell也显示命令提示符等目录中的所有链接目标?
发布于 2022-10-04 02:19:12
这取决于Powershell版本。请记住,dir只是Get-ChildItem的别名,而在PS5之前,GCI只是不包括linktype或target的属性。
对于PS 5+,这是可行的:
Get-ChildItem -Path "C:\temp\" -Force |
Where-Object { $_.LinkType -ne $null } |
ft FullName,Attributes,Linktype,Target
FullName Attributes LinkType Target
-------- ---------- -------- ------
C:\temp\hard Directory, ReparsePoint SymbolicLink {C:\Temp\temp\text.txt}
C:\temp\j Directory, ReparsePoint Junction {c:\temp\tmp\actss}
C:\temp\soft Directory, ReparsePoint SymbolicLink {C:\Temp\Log4j}对于PS 4,如果没有Linktype,我们需要检查ReparsePoints是否匹配,并且只得到以下输出:
Get-ChildItem -Path "C:\temp\" -Force |
Where-Object { $_.LinkType -ne $null -or $_.Attributes -match "ReparsePoint" } |
ft FullName,Attributes,Linktype,Target -auto
FullName Attributes Linktype Target
-------- ---------- -------- ------
C:\temp\J Directory, ReparsePoint
C:\temp\soft Directory, ReparsePoint
C:\temp\hard Archive, ReparsePoint因此,在后一种情况下,最好像前面提到的那样向cmd /c dir进行炮击。
https://stackoverflow.com/questions/73942032
复制相似问题