How to use pbcopy on Ubuntu

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.

This functionality is available by default on Ubuntu/Linux but can be easily replicated using available Linux functionality.

You can replicate pbcopy on ubuntu by utilising a similar tool called xclip which does exactly the same.  However its 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:

Shell

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

Shell

Then create an alias for pbcopy and pbpaste:

Shell

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

Shell

Script for pbcopy on ubuntu

I have created a quick script to help automate the configuration of pbcopy on ubuntu.

Shell

Please bear in mind, that due to the fact the script will be installing new software it will require elevated permissions to run. Typically I execute the script

Shell

For further information on How to execute a BASH script

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.

Shell

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

Shell

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.

Shell

Summary

This is an example of how flexible, adaptable and customizable the Linux Operating system is. Simply utilising the The alias Command you’re easily able to replicate functionality found on the MacOSX directly on your Linux system.

This provides you with the capability to customise your system to how you prefer to work with it. Taking time to learn and understand the Aliases in Linux will help you to tailor your system and decrease the amount of typing you need to do.

Gary Woodfine

Technical Director at Denizon
Gary is Technical Director at Denizon, an independent software vendor specialising in IoT, Field Service and associated managed services,enabling customers to be efficient, productive, secure and scalable in a way which helps them address and reduce their ecological impact.

Denizon's product line successfully integrate IoT, Artificial Intelligence and Blockchain technology to enable efficient, productive, secure and scalable solutions to help organisations address increasing energy demands, ecological impact and Health & Safety concerns of their staff.

Latest posts by Gary Woodfine (see all)