Clipboard

Linux

On Linux, the clipboard can be manipulated from the command line with xclip and xsel on Xorg, and with wl-copy and wl-paste (from the wl-clipboard package) on Wayland.

For Arch Linux:

$ sudo pacman --sync --refresh --needed \
    xclip \
    xsel \
    wl-clipboard

See output on stdout and also copy it to the clipboard

When studying and taking notes, or when writting tutorials or documentation in general, I somtimes want to run a program, see its output on STDOUT and also already copy that output to the clipboard at the same time (to avoid having to manually copying the output afterwards, as if we do this repeatedly, it becomes boring and time-consuming). It can be done with the combination of the programs mentioned above, tee and a few pipes or redirections.

xclip

Examples with xclip
$ echo hello | tee /dev/tty | xclip -in -sel clip

$ echo hello | tee >(xsel -in -sel -clip)

$ ruby -w ./main.rb | tee /dev/tty | xclip -in -sel clip

$ ruby -w ./main.rb | tee >(xclip -in -sel clip)

xsel

Examples with xsel
$ echo hello | tee /dev/tty | xsel -ib

$ echo hello | tee >(xsel -ib)

$ ruby -w ./main.rb | tee /dev/tty | xsel -ib

$ ruby -w ./main.rb | tee >(xsel -ib)

wl-copy

$ echo hello | tee /dev/tty | wl-copy

$ echo hello | tee >(wl-copy)

$ ruby -w ./main.rb | tee /dev/tty | wl-copy

$ ruby -w ./main.rb | tee >(wl-copy)