Is it possible to capture bash output to the OS X clipboard?
Asked
Active
Viewed 3.9k times
169
-
Similar: http://stackoverflow.com/questions/96024/is-it-possible-to-send-the-contents-of-a-text-file-to-the-clipboard-from-the-comm and http://stackoverflow.com/questions/1064762/is-there-an-environment-variable-that-contains-the-clipboard-contents – Dennis Williamson Jan 10 '10 at 03:30
3 Answers
293
The pbcopy command does this.
For example, this puts the output from ls
on the clipboard/pasteboard:
ls | pbcopy
And pbpaste does the reverse, writing to stdout from the clipboard:
pbpaste > ls.txt
You can use both together to filter content on the clipboard - here's a rot13:
pbpaste | tr 'a-zA-Z' 'n-za-mN-ZA-M' | pbcopy

martin clayton
- 76,436
- 32
- 213
- 198
6
In case you want to capture error messages, this will work:
cmd 2>&1 | pbcopy

qed
- 22,298
- 21
- 125
- 196
2
You can do this using the pbcopy
command:
pbcopy < ./path/to/file/or/output/stream

PatJ
- 5,996
- 1
- 31
- 37

Morgan Howell
- 21
- 1