It's simple, but you need an additional tool.
Install the package
xsel which provides an easy command to access the clipboard:
sudo apt-get install xsel
Find out which
$DISPLAY your desktop is using. Usually it should be
:0, but you can check it by running this command in a terminal emulator on your GUI desktop:
I will assume the output is
:0, replace that with your actual output in the following commands if it's different.
Copy the command you would like to execute in the TTY, e.g. using Ctrl+C.
Switch to the TTY you want to use, e.g. to TTY1 using Ctrl+Alt+F1.
Log in by typing your username and password.
Enter the full command you wish to run, but replace the part you want to insert from the clipboard with
$(DISPLAY=:0 xsel -ob).
For example if you copied a large list of packages to install, you could type this into the TTY:
sudo apt-get update && sudo apt-get install $(DISPLAY=:0 xsel -ob)
The clipboard snippet does not necessarily have to be at the end of your command though, it may appear anywhere.
To simplify things further, let's move this still a bit complicated
DISPLAY=:0 xsel -ob to a script. I'll name it
paste is already taken), but you can also call it differently.
To create the script file in a location where every user can run it without having to specify the full path (I recommend
/usr/local/bin for this) and to make it executable, simply run those two commands:
( echo '#!/bin/bash' && echo 'DISPLAY=:0 xsel -ob' ) | sudo tee /usr/local/bin/PASTE
sudo chmod +x /usr/local/bin/PASTE
Now you can simply embed
$(PASTE) into your commands on a TTY to insert the clipboard content from your desktop there.