pbcopy is a handy command that lets you copy any output from the OS X terminal without using the mouse to select the relevant text.
Normal users don’t have much use for the command line, but for most developers and techies working on the terminal is an everyday necessity. However if one isn’t familiar with some common commands completing even a small task on the terminal can become a tiresome activity. That’s why most people who have to use the command line often make it their business to know every trick and command out their in order to get things done as fast as possible. If you don’t know about this one, you’re soon gonna wish you’d heard of it earlier.
Copy/pasting text from the terminal is a common task, and without handy shortcuts like Ctrl+C and Ctrl+V it can be a bit tiresome to drag your mouse to select the text and then right-clicking to copy. It wastes precious seconds, plus it’s annoying when you have to reach for the mouse again and again. Even Windows has no way to copy from the terminal without using your mouse (we may see it in Windows 10, let’s wait and see). Fortunately in OS X there is.
Using the pbcopy command you can easily copy the output of the previous command to your clipboard and paste it wherever you like. All you need to do is use the pipe symbol with the output followed by the command like this:
[output] | pbcopy
It’s a really neat way to copy from the terminal. Combine it with its complimentary command ‘pbpaste’ and you can save yourself some trouble. pbpaste reads whatever data you have in your clipboard and writes it to the terminal. Together these commands will make running commands on terminal just a little bit easier. Check out the detailed documentation here.