Re: xargs verses exec

From: Radoulov, Dimitre <cichomitiko_at_gmail.com>
Date: Tue, 24 Jul 2012 21:24:06 +0200
Message-ID: <500EF656.6050807_at_gmail.com>



Hi Joel,

On 24/07/2012 20:50, Joel.Patterson_at_crowley.com wrote:
> It has come time to switch to xargs instead of exec. I have found two issues with xargs, but I'll only ask one now.
>
> Say I change to ORACLE BASE and do a find on 'all the subdirectories' piping through xargs, but... there are no files that meet the criteria -- say the extension is ".abc".
>
> cd ${ORACLE_BASE}
> find */cdump -name "*.abc" -type f -mtime +40 -print | xargs ls -ltr
>
> Then, the find command comes back with the contents of the ${ORACLE_BASE} directory.

GNU xargs has the -r/--no-run-if-empty option for this :).

That said, _most_ find implementations support the {} + syntax for xargs emulation:

-exec command {} +

               This variant of the -exec option runs the specified command on the selected files, but the

               command line is built by appending each selected file name at the end; the total number of

               invocations of the command will be much less than the number of matched files. The command

               line is built in much the same way that xargs builds its command lines. Only one instance of

               '{}' is allowed within the command. The command is executed in the starting directory.

Note also that with the above syntax you're completely bypassing the shell (i.e. no shell special/IFS characters related problems).

Regards
Dimitre

--
http://www.freelists.org/webpage/oracle-l
Received on Tue Jul 24 2012 - 14:24:06 CDT

Original text of this message