05/05/2016

Emulate pbcopy and pbpaste in Linux with xsel - Bash

One of nice tools I did use before are "pbcopy" and "pbpaste", which are simply copy and paste any data to and from clipboard in command line! It's a Mac OS tool, and unfortunately there is no port for Linux!

However you still can get the same functionality on Linux using "xsel" command! But you need some modification to make it works as same as pb tools.

Just edit your ".bashrc" file and add:
alias pcopy='xsel --clipboard --input'
alias ppaste='xsel --clipboard --output'

Once you did, you can use them just like original ones. e.g. if you want to copy a content of file:
# Get data from another command.
echo 'Linux is awesome!' | pcopy

# Get data directly from a file.
pcopy < /etc/fstab

And if you want to past what you have currently in your clipboard, just use pbpaste!
Now enjoy your Linux system! It's the best system as you know :-)
Powered by Blogger.

Hello, my name is Ahmed AbouZaid and this is my "lite" technical blog!

I'm a passionate DevOps engineer, Cloud/Kubernetes specialist, Free/Open source geek, and an author.

I believe in self CI/CD (Continuous Improvements/Development), also that "the whole is greater than the sum of its parts".

DevOps transformation, automation, data, and metrics are my preferred areas. And I like to help both businesses and people to grow.

Popular Posts