How do I copy text from my xterm without a mouse?

十年热恋 提交于 2019-12-02 16:38:24
strager

You can use GNU screen's copy and paste commands.

Quick tutorial:

  1. Open screen: screen (or screen myprog my args here)
  2. Run your program, producing output you want copied
  3. Enter copy mode: Control+a+[
  4. Move your cursor to the start point
  5. Hit Enter
  6. Move your cursor to the end point
  7. Hit Enter
  8. 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+\.

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
Silveri

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:

  1. Enter copy mode with Ctrl + B, [
  2. Move the cursor with the arrow keys and then start selection with Ctrl + Space
  3. Move the cursor to select the text/region to copy and then copy with Alt + W (this will immediately exit you from copy mode)
  4. 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.

The OP said he didn't want to do this, but here is a unix utils way to do it for posterity. If you learn these little unix utilities they can be quite powerful.

ls $( dirname $( grep error error.log | head -1 | cut -d " " -f 5- ) )

note: syntax from memory

You may send output directly to the concerned xterm using xterm device no. Here is the command.

xyz$ls /home/ankit/documents/etc/x/y/z > /dev/pts/0 

(or watever is the device name, You can get it using command 'w' for opened xterm)

Try it & hope this may solve your problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!