|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Difference between xargs and exec
Hi,
I have tried both the options in small dummy scripts, but somehow i can't differentiate between the two. find . -name H* -exec ls -l {} \; find . -name H* | xargs ls -l Both work the ditto way. Any help is appreciated. |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
find . -name H* -exec ls -l {} \; executes the command ls -l on each individual file.
find . -name H* | xargs ls -l constructs an argument list from the output of the find commend and passes it to ls. consider if the ouput of the find command produced: H1 H2 H3 the first command would execute ls -l H1 ls -l H2 ls -l H3 but the second would execute ls -l H1 H2 H3 |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Quote:
However the xargs solution will fail if the shell has trouble parsing the file names. Try: touch "stupid name" and then retry the two commands. There is a third solution that combines the best of both worlds. It is in Posix but not every version of the find command supports it. It's like the first syntax except that instead of \; you just use + to terminate the command. |
| The Following User Says Thank You to Perderabo For This Useful Post: | ||
reid (09-14-2011) | ||
|
#4
|
||||
|
||||
|
As Perderabo siad the + is a useful option if available, and is in POSIX but not implemented by all versions of find, most noticeably ( for a lot of people ) it is not found in the GNU version of find from the GNU find man page: Code:
-exec command +
This variant of -exec is not yet supported, but is required by POSIX. |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Wow,
Just some small confusions. Your + option works for me. How can i found out whether my find is Gnu or not. I have tried "what find" - no use. "stupid name" fails in xargs, but its executing in exec Even if i do a "ls stupid name", it gives me error. I have to quote it, does exec automatically quotes it parameters. Thanks |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Quote:
|
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Thanks,
Any idea about finding out whether my find in Gnu one or not. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| difference bewteen pipe, xargs, and exec | guessingo | Programming | 1 | 10-12-2011 12:28 PM |
| Difference between using xargs and backticks | msarro | Shell Programming and Scripting | 1 | 12-14-2010 08:57 PM |
| Difference in Using xargs | Karthikeyan K | AIX | 1 | 10-10-2008 08:14 PM |
| String substitution on find results inside exec/xargs | myndcraft | Shell Programming and Scripting | 2 | 05-17-2008 02:36 PM |
| MV files with xargs or -exec | malaymaru | Shell Programming and Scripting | 4 | 04-28-2008 10:40 AM |
|
|