Copy and Paste
After using a Mac for nearly 20 years, I’ve started looking for alternatives: idealistic (Linux), pragmatic (Windows), and something in-between (Chrome OS). Since it’s proving to be quite the learning opportunity, I thought I would try to document some of the experiences and discoveries (big and small) here.
On Linux, I have found myself missing the Mac’s pbcopy
and pbpaste
commands. If you’re not familiar with them, they use standard input and output to ease working with the clipboard on the command line.
For example, copying the output of a command to the clipboard is simply a matter of:
echo "Hello, World" | pbcopy
And pasting it back can be done equally easily:
echo $( pbpaste )
While there’s no native single purpose command on Linux, there’s a good discussion on Super User that suggests aliasing xsel
or xclip
. I have found xclip
works well for me on both Ubuntu and Linux Mint.
First, you’ll need to install xclip
:
sudo apt-get install xclip
After which it’s a matter of adding a couple of aliases (to ~/.zshrc
in my case)1:
alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -selection clipboard -o'
Now, you can use pbcopy
and pbpaste
with reckless abandon, as you might on a Mac.
-
Of course you can use
xclip
orxsel
directly, but I personally find it hard to remember the appropriate arguments. ↩