如何捕获bash输出到Mac OS X剪贴板?


Answers:


234

pbcopy命令做到这一点。

例如,这会将输出ls放在剪贴板/粘贴板上:

ls | pbcopy

pbpaste则相反,从剪贴板写入stdout:

pbpaste > ls.txt

您可以将两者一起使用以过滤剪贴板上的内容-这是rot13

pbpaste | tr 'a-zA-Z' 'n-za-mN-ZA-M' | pbcopy

5

如果您想捕获错误消息,这将起作用:

cmd 2>&1  | pbcopy

1

您可以使用以下pbcopy命令执行此操作:

pbcopy < ./path/to/file/or/output/stream
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.