当前位置: 移动技术网 > IT编程>脚本编程>Shell > Windows Powershell 管道和重定向

Windows Powershell 管道和重定向

2017年12月08日  | 移动技术网IT编程  | 我要评论
管道 把上一条命令的输出作为下一条命令的输入。 powershell管道 例如通过ls获取当前目录的所有文件信息,然后通过sort -descending对文件信

管道

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

powershell管道
powershell管道

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

ps c:\pstest> ls | sort -descending name | format-table name,mode

name                            mode
----                            ----
d.txt                            -a---
c.txt                            -a---
b.txt                            -a---
abc                             d----
a.txt                            -a---

重定向

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

ps c:\pstest> "powershell routing" >test.txt
ps c:\pstest> get-content .\test.txt
powershell routing
ps c:\pstest> "powershell routing" >>test.txt
ps c:\pstest> "powershell routing" >>test.txt
ps c:\pstest> "powershell routing" >>test.txt
ps c:\pstest> "powershell routing" >>test.txt
ps c:\pstest> "powershell routing" >>test.txt
ps c:pstest\> get-content .\test.txt
powershell routing
powershell routing
powershell routing
powershell routing
powershell routing
powershell routing
ps c:\pstest>

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网