Find the answer to your Linux question:
Results 1 to 9 of 9
hi friends, if we type a command such as "locate somefilename" in the terminal we will get all the paths to the file name as output. If i want to ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2010
    Posts
    5

    Post short cut to copy from terminal output


    hi friends,

    if we type a command such as "locate somefilename" in the terminal we will get all the paths to the file name as output. If i want to copy only one line from that output how do i do that without using mouse?i need terminal short cut to copy one line .i am using fedora 10. gnome desktop.

    thanks in advance ...

  2. #2
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    There are several ways to do this, depending on what you want.

    One option is to just redirect the output to a file, and use that file for whatever you want to accomplish (input to another program, etc.). It doesn't work for everything, but it will work as far as using the line as input.

    Another option would be to run GNU screen, which contains something called a copy buffer. You can select text with the keyboard, copy it, and paste it later.

    What exactly do you want to do with the copied data? That will help figure out the best solution.

  3. #3
    Just Joined!
    Join Date
    Dec 2010
    Posts
    5
    thanks Cabhan

    My requirement is that if i get any error while compiling using gcc or any other error in the shell i want to copy that particular error line or group of lines from the terminal for searching in the internet .please tell the short cut for this ...
    Last edited by yuvairt; 12-10-2010 at 05:50 AM.

  4. #4
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    I would suggest checking out the xclip program:
    xclip | Download xclip software for free at SourceForge.net

    This is a program that you can pipe strings into in order to copy them to the X clipboard.

    This does require that you have an X server running.

    This will also not work if you run a command, see its output, and then decide you want to copy it. You need to know that you want to copy the output beforehand.

    Are you running in a terminal under an X server? Or are you running in a pure commandline environment? If the latter, the only way I know how to copy text between programs in a pure commandline environment is to use screen.

  5. #5
    Just Joined!
    Join Date
    Dec 2010
    Posts
    5
    i have both type of teminals i.e pure command line and x server

    now only i have tried xclip & screen ...really they are good ...
    but screen is not looking that much natural .if any default shortcuts are available that will be good ...because we cann't expect that all the systems might have screen .

    thanks Cabhan.

  6. #6
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    So basically, the problem is that the clipboard is actually an X thing. Other programs can copy within a single problem (vi, Emacs, screen, etc.), but copying between programs requires that those programs have some connection (via screen or an X server or something like that).

    This is why I'm recommending screen: it's basically a way for multiple programs to run within a single context and it supports copy and paste of arbitrary output.

    screen is pretty common these days, and it is probably the best solution that I know of.

  7. #7
    Just Joined!
    Join Date
    Dec 2010
    Posts
    5
    thanks Cabhan ...

  8. #8
    Just Joined!
    Join Date
    Dec 2010
    Posts
    16
    Another useful way is to use a pipe, you can for example...
    uname -r > file.txt

    and the output of that operation will be stored into that file (and creates the file if it not exists).

  9. #9
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    This feature is technically called IO redirection (piping is a subset of IO redirection that involves redirecting the output of a command directly into another command).

    I agree that IO redirection is probably the easiest solution, but it has two major problems: it requires that you know that you want the output redirected from the very beginning, and it requires that the program you are copying into takes its data from stdin.

    In the case specified above where you run gcc and get an error, this case would require running gcc once to see that you get an error, and then a second time to redirect the output to a file.

    The other problem with this is that although the output would now be stored on disk, there would be no way to copy and paste it into a web browser.

    For many cases, IO redirection may be enough. But for yuvairt's case, I don't think it will work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •