LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-04-2006, 11:19 AM   #1
PirateJack
LQ Newbie
 
Registered: Aug 2005
Location: London, England
Distribution: RHEL3
Posts: 20

Rep: Reputation: 0
Processing file located using the FIND command


Say I want to find a file named foo.bar. I do the command find -name foo.bar
But how in the same command do I do something else to the newly located file?

For example how do I use the find command to find foo.bar and zip it in the same command...find -name foo.bar | ???

Or is there a way to do a command in the same way as brackets work in maths ie something like vi [find -name foo.bar] to let me open foo.bar in vi editor without knowing where it's located?

Any ideas?

Last edited by PirateJack; 04-04-2006 at 11:23 AM.
 
Old 04-04-2006, 11:40 AM   #2
zeitounator
Member
 
Registered: Aug 2003
Location: Montpellier, France, Europe, World, Solar System
Distribution: Debian Sarge, Fedora core 5 (i386 and x86_64)
Posts: 262

Rep: Reputation: 30
This will find any foo.bar file in directory /some/path and zip it as <foundfilename>.zip
Code:
find /some/path -name foo.bar -exec zip {}.zip {} \;
For more info and advance stuff to run commands on found files, see the -exec option in find man page

Have fun
 
Old 04-04-2006, 12:24 PM   #3
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,474

Rep: Reputation: 189Reputation: 189
For your vi example, try:

$ vi $(find -name foobar)

This will execute the find command in parentheses first and vi will execute on that output. It will work as long as there is not more than one "foobar" in your search path. If there is more than one foobar, it will open the first one found. That's basic bash shell programing if you want to delve into it more.
As noted above, find is frequently used with the exec command; in addition it is also frequently used with the xargs command:

http://mandrivausers.org/index.php?s...=26880&hl=find

http://www.linuxlaboratory.org/index...Intro_to_xargs

If you go through the above articles you will start to get some sense on how to string commands together using the output of find.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i get the proper path to a file through find command napster Linux - General 4 11-07-2005 05:35 AM
Command to find file with text chamanrana Linux - Software 10 12-02-2004 11:47 AM
Command to find out which package contains which file ? javeree Slackware 6 07-10-2004 07:35 PM
Yum update complains missing file (broken dep), but file can be located. davidas Linux - Software 0 03-27-2004 10:11 PM
Command to find total file size satimis Linux - Newbie 1 01-22-2004 12:19 PM


All times are GMT -5. The time now is 01:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration