Use pbcopy and pbpaste on Ubuntu

After using Mac for a couple of years for work reasons I got used to the pbcopy and pbpaste commands to copy and paste stuff from the terminal. Now that I’m back to Linux on my daily driver I figured out a simple way to do the same.

The process is straightforward:

  1. Install xclip:

    sudo apt install xclip
    
  2. Edit your .bash_aliases and add the new commands:

    alias pbcopy='xclip -selection clipboard'
    alias pbpaste='xclip -selection clipboard -o'
    
  3. Reload your bash configuration file:

    source ~/.bashrc
    
  4. Test your new aliases:

    echo "Hello World!" | pbcopy
    pbpaste
    

    You see “Hello World!” copied by your first command and pasted by the second. That’s it!