We can also copy and paste using only the command line.
xclip interacts with the same primary and clipboard selections mentioned above, reading from standard input and printing selection contents to standard output. This can be useful in many situations. For one thing, it guarantees that what you are copying is exact – it will include any non–printable characters as they are:
$ printf 'a\tb\0c' | xclip
$ xclip -out | od --address-radix=n --format=c --width=1
In the first command,
printf outputs the characters
a, Tab (
b, NUL (
c to standard output.
xclip reads that from standard input and saves it to the default (primary) selection of the X Window System clipboard. In the second command we print the contents of the primary selection to standard output and format it using
od into their individual characters.
odoptions in detail:
--address-radix=ndisables printing the offset of each line,
--format=cformats printable characters as themselves and non–printable characters as their
printf-style backslash escapes, and
--width=1outputs one byte per line.