I often have many terminals open when working (GNOME Terminal 3.4.1.1
, Bash
). Quite often I need to copy the results of one terminal into another. An common scenario:
terminalA> pwd
/home/hooked/foo
terminalB> cp * /home/hooked/foo
I usually end up copy pasting with the mouse. Is there a keyboard shortcut for what I'm trying to achieve?
Ctrl + Shift + c --> Copy
Ctrl + Shift + v --> paste
In terminal... Go to Edit > Keyboard Shortcuts... and this window opens...
you highlight the text (or double left click it) you want to copy with the mouse and Ctrl+Shift+C to copy and Ctrl+Shift+V to paste. Also you can highlight text with the mouse and use the middle mouse key/scroll wheel to paste.
Another solution: you do not need to use keyboard shortcuts at all!
Just mark what you want with the left mouse button (for example, double clicking a word), and paste it by clicking the middle mouse button in the other terminal. This is the "old style" X clipboard.
There are many situations where copying and pasting from the terminal is useful. However, in the situation you cited, I believe there's a better way.
Your situation involves operating on some path which was printed in another terminal window. You can copy and paste, but what if there are spaces in the name? Also, copying and pasting involves you moving your hand from the keyboard to the mouse to select the text, which is inefficient.
In your example, you wanted to work with
/home/hooked/foo
. I'm assumming that/home/hooked
is your home directory, which is the value of the environment variable$HOME
. So, you could refer to$HOME/foo
instead. But, inbash
and a number of other places,~
is a shortcut for$HOME
. Thus, you could refer instead to~/foo
.Then, there's tab completion. Suppose you had the following directory structure:
When you want to refer to
~/foo
, you can type this:~/f
TAB. The tab key does autocompletion. Play with it to learn how it works, and you'll stop typing things in full now. Thanks to tab completion, I freely use long filenames with spaces and other special characters--sometimes even characters not present on my keyboard--without any inconvenience, because I never have to actually type them or waste time copying and pasting.If you learn to use these tools (along with relative diretory paths if you don't already know about them), I predict you'll no longer find a need to copy and paste for filesystem operations.
A completely different approach would be to use a temporary file, like