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.

Terminals without CLIPBOARD selection

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

Intercepting commands’s 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.

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

A cheatsheet for common emulators

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: Some "No" entries in this table may be wrong. (Discuss in Talk:Copying text from a terminal#A cheatsheet for common emulators: "No" entries factual accuracy)

Until the "Notes" column states otherwise, the keys combination is Ctrl+Shift+c.

Emulator Selection → CLIPBOARD Selection → PRIMARY Keys combination Context menu → Copy Window menu → Copy Notes
atermAUR No Yes No No No
ETermAUR No Yes No No No
germinalAUR No Yes Yes Yes No
guake No Yes Yes Yes No
konsole No No Yes Yes Yes
lilyterm No Yes Yes Yes No Ctrl+Delete
lxterminal No Yes Yes Yes Yes
mate-terminal No Yes Yes Yes Yes
mltermAUR Yes Yes No No No
pantheon-terminal No Yes Yes Yes No
putty No Yes No No No
qterminalAUR No Yes Yes Yes Yes
roxterm No Yes Yes Yes Yes
rxvt No Yes No No No
sakura No Yes Yes Yes Yes
st No Yes No No No
terminator No Yes Yes Yes No
terminology No Yes Yes Yes No
termite No Yes Yes No No
tilda No Yes Yes Yes No
tinyterm (tinyterm-gitAUR) No Yes Yes No No
urxvt Optional Yes Yes No No Ctrl+Alt+c
XFCE Terminal (xfce4-terminal) No Yes Yes Yes Yes
xterm Yes Yes Optional No No [1]
yakuake No Yes Yes Yes No

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 selection-to-clipboard perl extension. See Rxvt-unicode#Cut and paste for details.

xterm

Access to the CLIPBOARD selection in xterm requires additional steps.