首页 > 开发 > PowerShell > 正文

Windows Powershell 管道和重定向

2020-03-26 19:19:10
字体:
来源:转载
供稿:网友

管道

把上一条命令的输出作为下一条命令的输入。

Windows,Powershell,管道,重定向
PowerShell管道

例如通过ls获取当前目录的所有文件信息,然后通过Sort -Descending对文件信息按照Name降序排列,最后将排序好的文件的Name和Mode格式化成Table输出。

PS C:/PStest> ls | sort -Descending Name | Format-Table Name,ModeName                            Mode----                            ----d.txt                            -a---c.txt                            -a---b.txt                            -a---ABC                             d----a.txt                            -a---

重定向

把命令的输出保存到文件中,‘>'为覆盖,'>>'追加。

PS C:/PStest> "Powershell Routing" >test.txtPS C:/PStest> Get-Content ./test.txtPowershell RoutingPS C:/PStest> "Powershell Routing" >>test.txtPS C:/PStest> "Powershell Routing" >>test.txtPS C:/PStest> "Powershell Routing" >>test.txtPS C:/PStest> "Powershell Routing" >>test.txtPS C:/PStest> "Powershell Routing" >>test.txtPS C:PStest/> Get-Content ./test.txtPowershell RoutingPowershell RoutingPowershell RoutingPowershell RoutingPowershell RoutingPowershell RoutingPS C:/PStest>

 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表