linux - [Solved-5 Solutions] Pipe tofrom the clipboard - ubuntu - red hat - debian - linux server - linux pc



Linux - Problem :

Is it possible to pipe to/from the clipboard in Bash ?

Linux - Solution 1:

Using alias xclip="xclip -selection c" otherwise you can't just use to Ctrl+v to paste it back in a different place.

echo test | xclip   
click below button to copy the code. By - Linux tutorial - team
Ctrl+v === test
click below button to copy the code. By - Linux tutorial - team

Linux - Solution 2:

On Mac OS X you might find these command line tools:

  • pbcopy
  • pbpaste

Example:

cat ~/.bashrc | pbcopy
click below button to copy the code. By - Linux tutorial - team

After that command content of the ~/.bashrc file is available for pasting with cmd+v shortcut.

Linux - Solution 3:

  • xclip
xclip - command line interface to X selections (clipboard) 
click below button to copy the code. By - Linux tutorial - team

Linux - Solution 4:

xsel on Debian/Ubuntu/Mint

# append to clipboard:
cat 'the file with content' | xsel -ib

# or type in the happy face and ...
echo 'the happy face and content' | xsel -ib

# show clipboard
xsel -b

# Get more info:
man xsel
click below button to copy the code. By - Linux tutorial - team

Install

sudo apt-get install xsel
click below button to copy the code. By - Linux tutorial - team

Linux - Solution 5:

Use bash script for reading the clipboard which works on multiple platforms.

#!/bin/bash
# WF 2013-10-04
# multi platform clipboard read access
# supports
#   Mac OS X
#   git shell / Cygwin (Windows)
#   Linux (e.g. Ubuntu)

#
# display an error
#
error() {
  echo "error: $1" 1>&2
  exit 1
}

#
# getClipboard
#
function getClipboard() {
 os=`uname`
      case $os in 
        # git bash  (Windows)
        MINGW32_NT-6.1)
          cat /dev/clipboard;;
        # Mac OS X
        Darwin*)
          pbpaste;;  
        # Linux 
        Linux*)
          # works only for X clipboard - a check that X is running might be due
          xclip -o;;
        *)
          error "unsupported os $os";;
      esac
}

tmp=/tmp/clipboard$$
getClipboard >$tmp
cat $tmp
# comment out for debugging
rm $tmp
click below button to copy the code. By - Linux tutorial - team

Related Searches to - linux - linux tutorial - Pipe tofrom the clipboard