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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Now that I have found with Locate, how to copy?
# 1  
Old 02-18-2010
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:
Code:
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!
# 2  
Old 02-18-2010
Code:
locate Yehu| sed -n '3p'| xargs -I {} cp {} /yourhome

Maybe you can leave out the -I {}; different on some versions of xargs iirc.
# 3  
Old 02-18-2010
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.
# 4  
Old 02-18-2010
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.
# 5  
Old 02-18-2010
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:
Code:
$ 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?
# 6  
Old 02-18-2010
Quote:
Originally Posted by dotancohen
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:
Code:
$ 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.
# 7  
Old 02-18-2010
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Locate the files in the first column and copy the files in 2nd column

#cat data.txt file1 folder1 file2 thisforfile2 file3 thisfolderforfile3 lata4 folder4 step 1: create the folder first in column 2 for i in `awk '{print $2}' data.txt` do mkdir /home/data/$i done step 2: locate the files in column1 and stored them into a file for i in... (17 Replies)
Discussion started by: kenshinhimura
17 Replies

2. Red Hat

Can't locate DBI.pm in @INC

my os details as follow bash-3.2$ cat /etc/redhat-release Red Hat Enterprise Linux Server release 5.8 (Tikanga) I run the following and encounter the following error bash-3.2$ mysqlhotcopy -? Can't locate DBI.pm in @INC (@INC contains:... (5 Replies)
Discussion started by: jediwannabe
5 Replies

3. Shell Programming and Scripting

Copy/print all lines between pattern is found in .log files

Hi, I have a folder with multiple (< 33) .log files. And I have to copy the lines between two patterns from all the .log files to a new file. (script file with a loop?) Thanks in advance. 1.log ... .. xx1> begin ... .. .. >>> Total: 2 Alarms .. .. (17 Replies)
Discussion started by: AK47
17 Replies

4. UNIX for Advanced & Expert Users

getting error "ssh-copy-id: not found"

Hello, i am trying to make an ssh connection from one server to another and invoke a script on another server. while doing this i want to do a passwordless ssh connection for the same, for which i have used the following command ssh-keygen -t rsa ssh-copy-id -i... (3 Replies)
Discussion started by: arwant
3 Replies

5. Linux

Help to locate the files

I m new to the linux environment.Help me with ur suggestions. How can i obtain the file names alone from ls -ltr output?? And those files should have been created before three months and earlier than that.. Thanks and wishes, Rupaa. (8 Replies)
Discussion started by: Rupaa
8 Replies

6. UNIX for Dummies Questions & Answers

command locate.

Hi, I am aware of the command locate/slocate. But when I try to search the file which is located in /tmp. Its not able to get it. I tried by updating the database also with the command updatedb. Is there any consern that the command 'locate' dont check /tmp??? And I knew that locate is the... (5 Replies)
Discussion started by: praveen_b744
5 Replies

7. Shell Programming and Scripting

How to copy file and locate in new folder?

Hi All, Please advise me how to make a copy of file from a list and store in one particular location? For example , I have aaa.txt which contains as below, But, those *usg files might be randomly store in different location.... > cat aaa.txt adc.usg dfdjkf.usg ugjfk.usg And I want... (3 Replies)
Discussion started by: cedrichiu
3 Replies

8. Shell Programming and Scripting

how can i check in csh if command found or not found ?

hello all im trying to use in sun Solaris the information received from the top command now i several machines that dont have install the top program so when im running the script im geting error saying after im running this code : set MemoryInfo = `top | grep Memory` if (... (2 Replies)
Discussion started by: umen
2 Replies

9. Solaris

Equivalent to locate

Does Solaris 10 have an equivalent to FreeBSD's `locate'? If not, what is the best way to search for files (allowing regexp) throughout the system? (5 Replies)
Discussion started by: Russell
5 Replies

10. UNIX for Dummies Questions & Answers

not able to locate SSH

In our unix environment I'm not able to locate where ssh is located. can any one guide me in finding the location of this tool. (5 Replies)
Discussion started by: bishweshwar
5 Replies
Login or Register to Ask a Question