How do I copy text from my xterm without a mouse?
I find XSel is useful in similar situations. It's a tool that manipulates the X selection. For example, this will store the output of your command to the clipboard:
grep error error.log | xsel -bi
You could also use tmux
which has similar capabilities to screen
. Once you're in tmux
and you have the output you want to copy, you can do the following to copy and then paste it:
- Enter copy mode with Ctrl + B, [
- Move the cursor with the arrow keys and then start selection with Ctrl + Space
- Move the cursor to select the text/region to copy and then copy with Alt + W (this will immediately exit you from copy mode)
- You can now paste (within
tmux
only) using Ctrl + B, ]
These instructiuons assume emacs key bindings are enabled. For the vi bindings see this comparison or just follow this step-by-step guide.
You can use GNU screen's copy and paste commands.
Quick tutorial:
- Open screen:
screen
(orscreen myprog my args here
) - Run your program, producing output you want copied
- Enter copy mode: Control+a+[
- Move your cursor to the start point
- Hit Enter
- Move your cursor to the end point
- Hit Enter
- Paste: Control+a+]
Screen is much more powerful than that (I use it to tab several virtual terminals without the need for a special terminal emulator, and also so that I don't loose my sessions when X crashes or something). To get out of screen, simply end your shell session, or type Ctrl+a, Ctrl+\.