Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

5 Answers

up vote 5 down vote accepted

Ctrl + Shift + c --> Copy

Ctrl + Shift + v --> paste

In terminal... Go to Edit > Keyboard Shortcuts... and this window opens... For further info...

share|improve this answer
    
I had no idea that the copy commands took in the buffer! I feel so stupid - thanks! –  Hooked Sep 19 '12 at 14:31
    
Then you can accept my answer ;) –  Sam Sep 19 '12 at 14:38
    
absolutely, though the site prevents me from doing so until some prerequisite time has elapsed. –  Hooked Sep 19 '12 at 14:41
    
Hey check the updates... –  Sam Sep 19 '12 at 14:46
add comment

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.

share|improve this answer
add comment

Another solution: you do not need to use keyboard shortcuts at all!

Just mark what you want with the middle mouse button (for example, double clicking a word), and paste it by clicking the right mouse button in the other terminal. This is the "old style" X clipboard.

share|improve this answer
add comment

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, in bash 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:

/
|-> home
    |-> hooked
        |-> foo
        |-> bar
        |-> buzz

When you want to refer to ~/foo, you can type this: ~/fTAB. 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.

share|improve this answer
add comment

A completely different approach would be to use a temporary file, like

terminalA> pwd > /tmp/somepwd

terminalB> cp * `cat /tmp/somepwd`
share|improve this answer
1  
This approach won't work if the directory name contains spaces or other characters that have a special meaning to the shell. –  Scott Severance Sep 19 '12 at 23:15
1  
Yes; however that's easily fixed with adding extra double quotes (cp * "`cat /tmp/somepwd`"). –  leftaroundabout Sep 20 '12 at 9:22
    
And, of course, such directory names are a very bad thing to have in the first place anyway, (though in fact Canonical choose to name that infamoous folder Ubuntu One...). At least, they're a problem in the OP's original example, too. –  leftaroundabout Sep 20 '12 at 9:35
    
Having spaces in filenames is hardly a bad idea. In fact, in many cases it's the best way in terms of readability and overall usability. Spaces in filenames never cause problems in sane code, and thanks to features such as tab completion they don't make filenames more difficult to type, either. My personal practice is to use any appropriate character (including spaces, exotic characters that I pull from the character map, etc.) when I expect to use the file/directory in a GUI at least on occasion. If I'm programming, I avoid spaces to comply with conventions. –  Scott Severance Sep 21 '12 at 8:30
    
I like using exotic characters, too – those should never be a problem, everything should be UTF-8 compliant. And you're right: sane code should handle spaces as well. But IMO, the file system should be fine with "insane" code as well, namely quick command-line Bash hacks; those typically are quite a bit more cumbersome to write if you want to be space-safe. — What I'd propose is to use the no-break-space-character (U+a0 " "): that looks fine in a GUI, prevents wrapping at inappropriate places (which makes it easier to copy paths from a GUI text field into a terminal), and is Bash-hack-safe. –  leftaroundabout Sep 21 '12 at 8:41
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.