如何将 bash 输出捕获到 Mac OS X 剪贴板?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1753110/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I capture bash output to the Mac OS X clipboard?
提问by Stephen Handley
Is it possible to capture bash output to the OS X clipboard?
是否可以将 bash 输出捕获到 OS X 剪贴板?
回答by martin clayton
The pbcopycommand does this.
该pbcopy命令做到这一点。
For example, this puts the output from ls
on the clipboard/pasteboard:
例如,这会将输出ls
放在剪贴板/粘贴板上:
ls | pbcopy
And pbpastedoes the reverse, writing to stdout from the clipboard:
而pbpaste则相反,从剪贴板写入标准输出:
pbpaste > ls.txt
You can use both together to filter content on the clipboard - here's a rot13:
您可以同时使用两者来过滤剪贴板上的内容 - 这是一个rot13:
pbpaste | tr 'a-zA-Z' 'n-za-mN-ZA-M' | pbcopy
回答by qed
In case you want to capture error messages, this will work:
如果您想捕获错误消息,这将起作用:
cmd 2>&1 | pbcopy
回答by Morgan Howell
You can do this using the pbcopy
command:
您可以使用以下pbcopy
命令执行此操作:
pbcopy < ./path/to/file/or/output/stream