Copying text from a terminal

Most mature terminal emulators permit users to copy or save their contents.

General approach

In graphical terminal emulators, contents are typically selectable by mouse, and can then be copied using the context menu, Edit menu or a key combination such as Ctrl+Shift+C.

Xorg

Some emulators do not support the CLIPBOARD selection natively, and copy data to the PRIMARY selection. For them xclip may be used:

$ xclip -o | xclip -selection clipboard -i

The above command reads data from the PRIMARY selection and writes it to CLIPBOARD selection.

Other clipboard managers such as autocutsel provide automatic synchronization between selection buffers.

Intercepting commands output

Use tee to intercept the output of a command.

$ command 2>&1 | tee output-file

After the command is executed, output-file will contain its output, while having displayed the output at the same time.

Accessing Linux terminal backlog

The backlog of a native terminal named /dev/ttyN may be accessed via /dev/vcsN. Hence, if one is working in /dev/tty1, the following snippet will let store the backlog in a file output-file:

# cat /dev/vcs1 >output-file

Comparison of common emulators

Unless the "Key combination" column states otherwise, the key combination is Ctrl+Shift+c.

EmulatorSelect to PRIMARY CLIPBOARD
Key combinationContext menuWindow menuSelect
AlacrittyYesYes
Yes
etermAURYes
YesYesYes
GuakeYesYesYes
KonsoleYesYesYesYesOptional
YesYes Yes
YesYesYesYes
YesYesYesYes
YesYesYes
YesYesYes
PuTTYYes
YesYesYesYes
YesYesYesYes
Yes
sakuraAURYesYesYesYes
stYesYes
TerminatorYesYesYes
YesYesYes
TermiteYesYes
TildaYesYesYes
urxvtYesYes Ctrl+Alt+cOptional
YesYesYesYes
xtermYesOptionalYes
YakuakeYesYesYesOptional

Special cases

putty

The xclip approach works for putty: one just has to remember that the xclip invocation should be done on the local computer (in another terminal), not on the remote machine to which putty is connected.

urxvt

Selecting text to CLIPBOARD requires the perl extension. See Rxvt-unicode#Cut and paste for details.

xterm

Access to the CLIPBOARD selection in xterm requires additional steps.

mlterm

In addition to Ctrl+Shift+c, you can use if you do not want to kill processes accidentally.

gollark: Read better.
gollark: Then we'll just have to use our abstract concept derealizer hyperspheres.
gollark: The US military is composed of matter held together using chemical bonds, so you're actually wrong.
gollark: Orbital laser countermeasures activated.
gollark: This should be stopped.
This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.