Copy to Clipboard from Command Line
If you've ever been debugging with a fellow developer, you'll hear "OK, execute that and let me know what it says". In this case, you can either manually copy the output and instant message the text over to them, or you can write the output to file with
>> , open the file, manually copy the contents, and paste it into IM. I experience this for a few hours recently and it was way to much work! Shouldn't there be a way to quickly place an execution's output directly into the clipboard just to save some time? You can with
Copy stdout to Clipboard
You'll use a single pipe to transfer the stdout result into the clipboard:
# command | pbcopy hg diff | pbcopy
git diff information is copied to the clipboard in this example; now you can show your colleague what you've changed.
Copy File Contents to Clipboard
In the case of copying file contents into the clipboard,
pbcopy goes first:
# pbcopy < file.ext pbcopy < circle.yml
The complete file contents are instantly copied to the clipboard for easy sharing.
Pasting to File
So what if you want to paste the clipboard contents into a new or existing file? Use
#pbpaste > file.txt pbpaste > commands.txt
The clipboard contents will be placed into the given file.
pbcopy will be a big timesaver for me moving forward. Manually copy and pasting information is with the mouse or trackpad is inconvenient and time-consuming. These types of command line techniques can make us more proficient, skilled developers!