You can do this using a program like
xclip - command line interface to X selections (clip‐
Once you have installed it, you can use it to connect to your X clipboard. Unfortunately, this won't work in your
mysql environment (it has its own buffer for copied lines) but it will if you want to run a 'normal' command. For example :
$ This is a long command line
Type CtrlA to go to the beginning of the line, enclose the command in quotes then echo it:
$ echo -e "This is a long command line" |xclip
You now have "This is a long command line" in your middle click clipboard.
If you want to paste without using a mouse, it will depend on where you are pasting. You can paste into another terminal by running:
$ xclip -o
You can paste into the same terminal, simply by killing (cutting) the command with CtrlK and then pasting with CtrlY.
You can also save commands across terminals using bash's history. Add this line to your
PROMPT_COMMAND='history -a; history -r'
PROMPT_COMMAND is a special bash variable. If it is set the value is executed as a command before issuing a new prompt.
history -a will write the history of the current session to the history file and
history -r will reload that file. This means that every command you run will be immediately written to the history file.
Now when you run a long command line, you can switch to another terminal and hit return (just to run
$PROMT_COMMAND, alternatively, open a new terminal window) and it will be accessible to this terminal's history. If you now hit Up you can run it on the new terminal.