How To Imitate (Replicate) pbcopy And pbpaste Commands On Linux
How To Imitate (Replicate) pbcopy And pbpaste Commands On Linux
pbcopy on a mac enables you to copy the standard input from terminal window to your clipboard enabling you to paste it to other applications.
This functionality is not available by default on Ubuntu/Linux but can be easily imitate using available Linux commands
You can imitate pbcopy and
pbpaste on ubuntu/linux by using similar tool called xclip
which does exactly the same. However its syntax is a little complicated it required more options/switches. So, I am going to imitate it with pbcopy and pbpaste
command.
Fortunately, OS X and Linux *nix based we can make use of the The alias command to replicate the pbcopy and pbpaste functionality in ubuntu/linux.
If you haven’t previously installed xclip simply run the following command in your terminal:
$ sudo apt-get install xclip -y
Edit your BASH settings file using your favorite text editor. I will be using Vim, but feel free to use gedit or nano etc.
$ vi ~/.bashrc
Then create an alias for pbcopy and pbpaste:
alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -selection clipboard -o'
Close and save the file then just refresh your bash to import your new settings by running following command on terminal
$ source ~/.bashrc
Let us see examples.
The pbcopy command will copy the text from stdin into clipboard buffer. For example, have a look at the following example
$ echo "Welcome To View Demo!" | pbcopy
The above command will copy the text "Welcome To OSTechNix" into clipboard. You can access this content later and paste them anywhere you want using Pbpaste command like below.
$ echo `pbpaste`
Welcome To View Demo!
Comments
Post a Comment