首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PowerShell dir显示所有符号链接目标,如命令提示符

PowerShell dir显示所有符号链接目标,如命令提示符
EN

Stack Overflow用户
提问于 2022-10-04 00:27:43
回答 1查看 96关注 0票数 1

当您在命令提示符cmd.exe中使用cmd.exe时,

代码语言:javascript
复制
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中尝试同样的方法时,您会得到

代码语言:javascript
复制
PS C:\path\to\somewhere> dir
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----l        2022-10-03     20:16                link

如何使PowerShell也显示命令提示符等目录中的所有链接目标?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-04 02:19:12

这取决于Powershell版本。请记住,dir只是Get-ChildItem的别名,而在PS5之前,GCI只是不包括linktypetarget的属性。

对于PS 5+,这是可行的:

代码语言:javascript
复制
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是否匹配,并且只得到以下输出:

代码语言:javascript
复制
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进行炮击。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73942032

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档