Linux: xclip to place content on the clipboard

If you are using Linux with graphical X interface and need to copy to the clipboard, the ‘xclip‘ utility works similar to ‘pbcopy’ on a Mac terminal and will place the content unto your clipboard.

Here is the basic usage:

sudo apt install xclip -y

# copies to clipboard
echo "hello" | xclip -selection clipboard

# grabs from clipboard
xclip -selection clipboard -o

If you want to avoid typing the ‘-selection clipboard’ flag every time, then create an alias loaded with your profile.

alias xclip='xclip -selection clipboard'

REFERENCES

xclip man page