Now that I have found with Locate, how to copy?

Once I have the output of a command, can I use that output without typing it in or resorting to complicated find/sed gibberish? Surely this is a common enough position to be in that Bash would have a facility for it built in?

For instance:

dotancohen@dcl:~$ locate Yehu
/usr/share/fonts/X11/Type1/YehudaCLM-Bold.afm
/usr/share/fonts/X11/Type1/YehudaCLM-Bold.pfa
/usr/share/fonts/X11/Type1/YehudaCLM-Light.afm
/usr/share/fonts/X11/Type1/YehudaCLM-Light.pfa
dotancohen@dcl:~$

Now I know that I want to copy the third result to my $HOME folder. How can I do that simply, without chaining a bunch of tools together or typing it in from the beginning?

Thanks!

locate Yehu| sed -n '3p'| xargs -I {} cp {} /yourhome

Maybe you can leave out the -I {}; different on some versions of xargs iirc.

Thanks, Zaxxon. I had foud examples of this while googling, however, I wanted to know if there is a simple way of doing this, without chaining together three tools as in your example.

Any file manager lets the user select a file displayed and move it easily and intuitively. Would that also not be the case with bash? I know that bash is not a file manager, but it is a well-developed, popular tool that is often used for managing files.

What seems complex/awkward can also been seen from a point of view that you have far many more options of doing things with files etc. than in a file manager. Options that are in a file manager are just a little bit you can do in a shell. Especially you can do automation, write scripts and so on which you can't do with a file manager.
If you like a file manager etc. you might want to use some graphical desktop like Gnome or KDE. They bring filemanagers with them.
Also I did not use a file manager on any OS yet, that I could say, that it should take the 3rd file in the list and copy it somewhere. I always had to manually move the mouse cursor and click and drag some options.

Actually, I do use KDE. In Dolphin (and Konqueror before that) the user could easily move the selection to the third file via the arrow keys, Ctrl-C, F6 to the addressbar, type in the path (with tab-completion), then Ctrl-V to the right place.

But the question is not only of file managers, that was only an example. Another example might be looking for a package to install:

$ aptitude search qt | grep ruby
p   libqt0-ruby1.8                  - Qt3 bindings for Ruby
p   libqt4-ruby                     - Qt 4 Ruby bindings
p   libqt4-ruby1.8                  - Qt 4 bindings for Ruby
p   libqt4-ruby1.8-dev              - Qt 4 bindings for Ruby - development files
p   libqt4-ruby1.8-examples         - Qt 4 bindings for Ruby - example files
p A libqtruby4shared2               - internal library for Qt 4 Ruby bindings
$

Now I know that I want to install the second and fifth packages. Must I manually type in "sudo apt-get install libqt4-ruby libqt4-ruby1.8-examples"? Why can't there be a simple "sudo apt-get install ^2 ^5"? Should I file a feature request at bash? Is this not something that would be useful to many people?

The problem is that the shell isn't even looking at the output of your first command. The shell's fd for stdout is simply being copied into the subprocess that is running find/aptitude/etc. and that is outputing directly to your console.

You could write a short script or alias to select lines that you want so that "aptitude search qt | grep ruby | scriptA 2 5" would pull out those two lines and put them in a hidden file that can be found by a second script. Then "scriptB sudo apt-get install" would run the install on every line of the file.

> The problem is that the shell isn't even looking at
> the output of your first command. The shell's fd
> for stdout is simply being copied into the
> subprocess that is running find/aptitude/etc. and
> that is outputing directly to your console.

Thanks, I did not realize how the different parts work together. Actually, I still don't, but now I have some terms to google on.

> You could write a short script or alias to select
> lines that you want so that "aptitude search qt |
> grep ruby | scriptA 2 5" would pull out those two
> lines and put them in a hidden file that can be
> found by a second script. Then "scriptB sudo
> apt-get install" would run the install on every line
> of the file.

That might be a good exercise, I'll try that. Thanks.

---------- Post updated at 05:10 PM ---------- Previous update was at 05:03 PM ----------

I found screen this morning, which does most of what I am looking for:
Screen - Gentoo Linux Wiki
GNU Screen: an introduction and beginner's tutorial || kuro5hin.org