Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 04-04-2006, 10:19 AM   #1
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 I do the command find -name
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 and zip it in the same command...find -name | ???

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

Any ideas?

Last edited by PirateJack; 04-04-2006 at 10:23 AM.
Old 04-04-2006, 10:40 AM   #2
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 file in directory /some/path and zip it as <foundfilename>.zip
find /some/path -name -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, 11:24 AM   #3
Senior Member
Registered: Oct 2003
Posts: 2,653

Rep: Reputation: 236Reputation: 236Reputation: 236
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:

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.


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 04:35 AM
Command to find file with text chamanrana Linux - Software 10 12-02-2004 10:47 AM
Command to find out which package contains which file ? javeree Slackware 6 07-10-2004 06:35 PM
Yum update complains missing file (broken dep), but file can be located. davidas Linux - Software 0 03-27-2004 09:11 PM
Command to find total file size satimis Linux - Newbie 1 01-22-2004 11:19 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:04 PM.

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