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, I'm a passionate Tech Lead DevOps Engineer. 👋

With 16+ years of open-source contributions, 12+ years of professional hands-on experience in DevOps, and an M.Sc. in Data Engineering from Edinburgh Napier University (UK), I enjoy facilitating the growth of both businesses and individuals.

I specialize in Cloud-Native and Kubernetes. I'm also a Free/Open source geek and book author. My favorite topics are DevOps transformation, automation, data, and metrics.

Contact Me

Name

Email *

Message *

Start Your DevOps Engineer Journey!

Start Your DevOps Engineer Journey!
Start your DevOps career for free the Agile way in 2024 with the Dynamic DevOps Roadmap ⭐

Latest Post

2023 Highlights

Image generated with Craiyon . Finally, 2023 is over! What a year! One more crazy year, but it was the culmination ...

Popular Posts

Blog Archive