2015-04-27 71 views
2

PowerShell中是否有某种方法来模拟Linux ls -l命令的行为?等效于Linux的Windows PowerShell`ls -l`

我想看看符号链接指向什么。具体来说,我使用PowerShell New-Symlink实用程序,我想知道-Path在磁盘上的位置。

(是的,我知道 - 路径,因为我创造了它自己,但我想要一个ls -l相当于在其他几次。)

回答

3

看来PowerShell不支持这个开箱即用。 Here's an article explaining how to use dir in PowerShell to show if there is a symbolic link, but it doesn't show the target of the link。要显示链接的目标,您有两个选项。首先使用fsutil reparsepoint query或从命令提示符处使用dir。两者都有缺点。第一个以十六进制数据形式提供目标路径,第二个必须从命令提示符处运行,如powershell别名为dirGet-ChildItem(不显示符号链接)。

试试这个

Get-ChildItem | % { fsutil reparsepoint query $_ } 
cmd /c dir /a:l 

最好的答案我可以想出在下面的(使用正则表达式匹配的组中提取更多的信息,如果需要的话):

$PATH="C:\tmp" 
cmd /c dir $PATH | ? { $_ -match '([\d\.]+)\s+([\d:]+)\s+(\S+)\s+([^\[]+)\s*\[?([^\]]*)\]?' } | % { New-Object -TypeName PSCustomObject -Property @{Name=$matches[4];Target=$matches[5]}} 

输出将类似于至此

Target              Name 
------              ---- 
                  . 
                  .. 
                  file.txt 
C:\tmp\file.txt            symlink.txt