Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 870
Stephen Handley Avatar asked Oct 17 '22 18:10

Stephen Handley


People also ask

How to copy terminal output to clipboard Mac?

Command-C and Command-V work as expected if you can get the output selected, though. Command-C and Command-V works fine but you have to select the output using your mouse as you mentioned.

What is OSX Pbcopy command?

pbcopy will allow you to copy the output of a command right into your clipboard. Vice-versa for pbpaste — it will allow you to paste your clipboard right into your terminal. # This will copy all the content within a file. $ cat myfile. txt | pbcopy# This will output the contents of your clipboard.

How do I use Pbcopy on Mac?

And yes you can do use the pbcopy and pbpaste commands at the terminal and then interact with them again from the GUI of MacOS by using the standard Mac copy and paste keyboard shortcuts of Command+C and Command+V. It goes the other direction too, a copy from the GUI can be pasted with pbpaste at the command line.


1 Answers

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
like image 91
martin clayton Avatar answered Nov 15 '22 16:11

martin clayton