LinuxQuestions.org
Review your favorite Linux distribution.
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 09-14-2004, 08:13 AM   #1
rytrom
LQ Newbie
 
Registered: Jul 2003
Posts: 27

Rep: Reputation: 15
What's difference btw. -exec and xargs


I want to findn an jar containing particular class. So I execute it with help of -exec clause:

find . -name "*.jar" -exec jar -ft '{}' \;|egrep "MyClass";

another way to do it is with help of -xargs:

find . -name "*.jar" |xargs -n1 jar -ft| egrep "MyClass";


First question is what 's the difference behind these calls or actually btw. exec and xargs clauses?

And second questino is how to print all file names (found jars) that suit to the find command?
 
Old 09-14-2004, 08:50 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
2) use '-print' option to the find cmd
 
Old 09-14-2004, 10:25 AM   #3
Linux24
Member
 
Registered: Aug 2004
Distribution: Mandrake 10.1
Posts: 204

Rep: Reputation: 30
Re: What's difference btw. -exec and xargs

Quote:
Originally posted by rytrom
I want to findn an jar containing particular class. So I execute it with help of -exec clause:

find . -name "*.jar" -exec jar -ft '{}' \;|egrep "MyClass";

another way to do it is with help of -xargs:

find . -name "*.jar" |xargs -n1 jar -ft| egrep "MyClass";


First question is what 's the difference behind these calls or actually btw. exec and xargs clauses?

And second questino is how to print all file names (found jars) that suit to the find command?
There is a distinct difference. The first command will run everything one at a time. xargs, on the other hand, will run everything after find is finished running.

Consider this..

1. Use find to find three files

2. Use -exec to tar the files: You get one tarball for each file.

3. Use | xargs to tar the files. : You get one tarball with all the files.

That's the difference.
 
Old 09-14-2004, 04:42 PM   #4
rytrom
LQ Newbie
 
Registered: Jul 2003
Posts: 27

Original Poster
Rep: Reputation: 15
thanks for the answers I got the point. Simply in my case (since I succeeded to print merely class files but not jars) the output of -exec and xargs was almost the same I was confused a bit.

-print doesn't work becaues next pipe eats a found jar's name (jar -tfv) . To pritn a jar's name whose list containes a searhed class a sript must be used like:

for i in `find . -name '*.jar'`;do\
if jar -tf $i|grep "MyClass.";then\
echo "in file $i";\
fi;\
done
 
  


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
Several "find -exec" and "find | xargs" questions thanhvn Programming 4 12-02-2005 02:04 PM
what is the difference between Fork & exec augustus123 Linux - Newbie 1 11-29-2004 08:32 AM
xargs question reitzell Linux - Newbie 4 07-04-2004 03:36 AM
wts difference btw newbie and member farhan LQ Suggestions & Feedback 7 04-01-2003 10:57 PM
difference btw tar.gz and .tgz chr15t0 Slackware 15 09-03-2002 11:29 PM


All times are GMT -5. The time now is 08:28 AM.

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