What's like OSX's pbcopy for Linux

if you have X installed you may try xsel in this way :

alias pbcopy='xsel --clipboard --input'
alias pbpaste='xsel --clipboard --output'

or with xclip :

alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -selection clipboard -o'

now you can use'em :

echo 'go to my clipboard' | pbcopy

when I don't have X I use GNU Screen functionality to copy between open shells in a session using keyboard

to copy : Ctrl-a -> Esc -> go to wanted position * -> Space (to begin selecting) -> press k to go forward mark text -> Enter

to paste : Ctrl-a + ]

* movements are done with vim like key bindings (j, k, l & m).


Put a script like this called pbcopy in your bin folder:

#!/bin/bash
xclip -i -sel c -f |xclip -i -sel p

This will put STDIN in both your selection buffer and clipboard:

echo Hello world |pbcopy

To expand on the solutions of @Erik and @xpixelz; these two scripts should work on both platforms:

pbcopy:

#!/bin/bash
__IS_MAC=${__IS_MAC:-$(test $(uname -s) == "Darwin" && echo 'true')}
if [ -n "${__IS_MAC}" ]; then
  cat | /usr/bin/pbcopy
else
  # copy to selection buffer AND clipboard
  cat | xclip -i -sel c -f | xclip -i -sel p
fi

pbpaste:

#!/bin/bash
__IS_MAC=${__IS_MAC:-$(test $(uname -s) == "Darwin" && echo 'true')}
if [ -n "${__IS_MAC}" ]; then
  /usr/bin/pbpaste
else
  xclip -selection clipboard -o
fi

Tags:

Linux

Macos