How do I capture bash output to the Mac OS X clipboard?

MacosBashTerminalClipboard

Macos Problem Overview


Is it possible to capture bash output to the OS X clipboard?

Macos Solutions


Solution 1 - Macos

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

Solution 2 - Macos

In case you want to capture error messages, this will work:

cmd 2>&1  | pbcopy

Solution 3 - Macos

You can do this using the pbcopy command:

pbcopy < ./path/to/file/or/output/stream

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionStephen HandleyView Question on Stackoverflow
Solution 1 - Macosmartin claytonView Answer on Stackoverflow
Solution 2 - MacosqedView Answer on Stackoverflow
Solution 3 - MacosMorgan HowellView Answer on Stackoverflow