Copy and Paste to and from Clipboard via Linux Terminal

Sometimes you just want to copy or paste a file directly from the terminal.

Mac users have simple single commands called pbcopy and pbpaste.

We have the slightly less elegant xsel or xclip

To be able to use pbcopy and pbpaste just like Mac terminal users, all we have to do it is :

sudo apt-get install xclip -y
alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -selection clipboard -o'

Now you can just copy the contents of a file to clipboard with
pbcopy filename.txt
Or you can paste contents of clipboard to a file with
pbpaste > filename.txt