I ran up against this question, and i found it quite interesting.
While researching for that, i found out that a solution had been posted already here on AskUbuntu
, plus multiple times on StackOverflow
and on Unix & Linux
, but all the solutions provided involved the use of xclip
or xsel
, which are not available in a default Ubuntu
installation (i.e. they're not present in a Live DVD, for example).
Question: How to copy the stdout of a command to the clipboard in a default Ubuntu installation?
Copy stdout to the clipboard without installing additional software
Although it seemed impossible to me at first (and it is a bit of a detour), it is very well possible without additional software. The only thing needed is
python
, like it is installed from a fresh install.This solution uses
python
's ability to copy text to the clipboard, and make it available to other applications, as explained (a.o.) here.The construction
terminal_log.txt
The command(s) that run in the terminal are followed by
| tee /path/to/terminal_log.txt
, e.g.The output will be in the terminal, as well as written to
terminal_log.txt
The result of the example above:
If I open
gedit
and press Ctrl+VHow to setup
terminal_log.txt
terminal_log.txt
, save it asread_output.py
Start the script with the command
Run in (another) terminal your command, followed by:
| tee /path/to/terminal_log.txt
The output of your command is copied to the clipboard
If you use it frequently, you could run it as a startup application.
The script
Additional information
Will not copy
stderr
to the clipboard. To copy bothstdout
andstderr
to the clipboard, use:as explained here