Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I want to use part of the output of a command run from the command line in another xterm, or as part of a different command. For instance:

> grep error error.log error: can't find file ~/<some very long path>/thisfile 

and I want to do this:

>ls ~/<some very long path>/ 

I know two ways to do this:
1. copy ~/<some very long path>/ with the mouse.
2. use some combination of head/tail/awk/sed/perl/cut/etc... to extract only what I need from the output and then use that inside backticks.

Is there any way to copy text without using the mouse? The example that comes to mind is visual mode inside VIM, but I don't know how to do that inside the xterm.

like image 596
Nathan Fellman Avatar asked Nov 23 '08 06:11

Nathan Fellman


People also ask

How do you copy in terminal without a mouse?

Method 1: Using keyboard shortcuts for copy pasting in the terminal. On Ubuntu and many other Linux distributions, you can use Ctrl+Insert or Ctrl+shift+C for copying text and Shift+Insert or Ctrl+shift+V for pasting text in the terminal.

How do I paste in xterm without a mouse?

Then middle-click to paste the text. If you want to use the traditional cut/copy/paste commands, you can't use ctrl-X, ctrl-C, ctrl-V with xterm because those either generate interrupts or are passed through to applications. So you have to have to use ctrl-shift-X/C/V instead when cutting or pasting in the xterm.

How do I copy files in xterm?

The “CLIPBOARD” selection buffer is used for the cut-and-paste functions that most users are familiar with: Selecting the “cut”, “copy” or “paste” menu items from the application's “Edit” menu, or using the corresponding CTRL-X, CTRL-C, or CTRL-V shortcut keys.

How do you copy text in terminal?

Alternatively, you can press Shift + Ctrl + C . Highlight the text portions you wish to copy with color and font attributes, then right click on the text portion and select Copy as HTML. Right click in the Terminal and select Paste. Alternatively, you can press Shift + Ctrl + V .


1 Answers

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+\.

like image 80
strager Avatar answered Sep 20 '22 20:09

strager