Ubuntu – How to cut and paste terminal I/O without using the mouse

bashcommand linegnome-terminalsearch

I want to search and cut text from command output in a terminal so I can use it in subsequent command line invocations or just in an editor session.

Is there any way to easily run a regular expression against the output of a terminal and cutting results without touching the mouse?

My requirements are:

  • it should work while working with remote machines through ssh. In those machines I can not install extra software there so the solution must be local.
  • if possible, it must be "always present". For instance, if I'm running a long process and suddenly it fails I'd like to be able to grep through the output without having to start the process again with a prepared environment.

Best Answer

screen(1) allows you to copy/paste using the keyboard, but it requires that you run your shell/process inside screen.

To copy, hit Ctrl+A [, move the cursor (using the arrow keys) to the start point and hit (RETURN), move the cursor to the end point and hit . The marked text is now copied.

To paste, hit Ctrl+A ]

This solution also applies to Byobu, since Byobu is just a wrapper around screen.