When you constantly flip through different operating systems, during development, you are bound to get commands confused. For me one of those commands is pbcopy.

pbcopy on a mac enables you to copy the standard input from terminal window to your clipboard enabling you to paste it to other applications

You can replicate pbcopy on ubuntu by utilising a similar tool called xclip which does exactly the same.  However it’s syntax is a little too verbose and I prefer to use OS X pbcopy command.

Fortunately due to the fact that OS X and Linux *nix based we can make use of the The alias Command to replicate the pbcopy functionality in ubuntu.

how to configure pbcopy on ubuntu

If you haven’t previously installed xclip simply run the following command in your terminal window:

Edit your BASH settings file using your favourite text editor.  I’ll be using nano, but feel free to use Gedit or Vim etc.

Then create an alias for pbcopy and pbpaste:

Close and save the file then just refresh your bash to import your new settings

how to use pbcopy on ubuntu

After you have finished the configuration steps above you can simply use pbcopy on your ubuntu machine in much the same way you’ll utilize it on the mac.

This will copy your ssh public key and you can test if this works by pasting it into a Gedit text file.
This functionality also comes in very handy in situations when you need to copy the contents of your php info. For instance, when you need to configure xdebug to enable debugging for PHP.

You could use xclip to copy the contents

Or if you have taken the time to configure the short cut above you can make the command a lot easier to remember by removing some of the verbosity.

Gary Woodfine

Founder & CTO of threenine.co.uk. Experienced full stack software developer well versed in delivering web & mobile applications utilizing cloud architectures. Areas of specialty include cross platform development in .net , PHP, JavaScript.