Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

find + xargs: how do I handle space in the path

13 views
Skip to first unread message

mathieu

unread,
Jun 14, 2007, 4:57:18 AM6/14/07
to
Hello,

There must be something easy I am missing. But how am I supposed to
handle space in the path when using xargs (from the output of find for
example).

Thanks
-Mathieu

ramesh.t...@gmail.com

unread,
Jun 14, 2007, 5:54:44 AM6/14/07
to


Seems we have option in Linux. Not sure whether it is there in other
platforms.

OPTIONS
--null, -0
Input filenames are terminated by a null character
instead of by
whitespace, and the quotes and backslash are not
special (every
character is taken literally). Disables the end of file
string,
which is treated like any other argument. Useful when
arguments
might contain white space, quote marks, or backslashes.
The GNU
find -print0 option produces input suitable for this
mode.

Or otherwise i think we can use -exec option of find. But xargs is
faster than exec option

mathieu

unread,
Jun 14, 2007, 9:14:06 AM6/14/07
to

$ touch "/tmp/space in
path"
~

$ find /tmp/space* | xargs
ls
~
ls: /tmp/space: No such file or directory
ls: in: No such file or directory
ls: path: No such file or directory

$ find /tmp/space* -print0 | xargs -0
ls
~
/tmp/space in path

sweet !

Thanks,
-Mathieu

Geoff Clare

unread,
Jun 15, 2007, 8:41:51 AM6/15/07
to
ramesh.thangamani wrote:

> Or otherwise i think we can use -exec option of find. But xargs is
> faster than exec option

Only if you terminate the -exec with ';'. If you terminate it
with '+', -exec should be (slightly) faster than piping to xargs,
as find then does the same argument aggregation that xargs would
have done, but without the overhead of writing all the pathnames
to a pipe and reading them back.

--
Geoff Clare <net...@gclare.org.uk>

sjde...@yahoo.com

unread,
Jun 15, 2007, 11:37:36 AM6/15/07
to

On what version of find? That's certainly not usual, but it's pretty
cool.

Daniel Rock

unread,
Jun 15, 2007, 2:33:08 PM6/15/07
to
sjde...@yahoo.com <sjde...@yahoo.com> wrote:

> Geoff Clare wrote:
>> Only if you terminate the -exec with ';'. If you terminate it
>> with '+', -exec should be (slightly) faster than piping to xargs,
>> as find then does the same argument aggregation that xargs would
>> have done, but without the overhead of writing all the pathnames
>> to a pipe and reading them back.
>
> On what version of find? That's certainly not usual, but it's pretty
> cool.

On all standards compliant find implementations:

http://www.opengroup.org/onlinepubs/009695399/utilities/find.html

(first introduced in SVR4)

--
Daniel

Sven Mascheck

unread,
Jun 16, 2007, 7:06:08 AM6/16/07
to
Daniel Rock wrote:
> sjde...@yahoo.com wrote:

>> On what version of find?
>

> On all standards compliant find implementations:
> http://www.opengroup.org/onlinepubs/009695399/utilities/find.html
> (first introduced in SVR4)

and in practice:

- implemented in all SunOS 5.x versions, but only documented since SunOS 5.9.

- implemented and documented on UnixWare ("SVR4.2") at least since 2.1.

- implemented but not documented on other earlier SVR4 versions,
like Unicos 9.0.2.2 (Cray) and EP/IX 2.2.1AA (Control Data).

Later it was added to futher implementations:

- implemented and documented on HP-UX since 11.x.
(The first argument is wrongly ignored on earlier 11.x; that is
"find . -exec echo x {} +" works correct. It was fixed with a patch
for 11.11 (between find revision PHCO_25905 and PHCO_29692) - pointed
out by F.Anwander and P.Holzer in <3iakecF...@individual.net> ff.)

- implemented and documented on FreeBSD since 5.0.

- implemented in the AST toolchest since 99-02-14, but not documented.
At the time of this writing, AST 2006-01-24, the braces must be omitted
to get the expected behaviour.

- documented to be syntactically accepted on AIX 5.3 (from the manpage,
but i don't know yet, if it's actually implemented)

- sfind implements it at least since release 0.92 (07/2004)

- GNU findutils introduced it with 4.2.12 (Jan 2005); but bugs still
were fixed in
4.2.19 (Mar 2005), 4.2.26 (Nov 2006) ("Applied bugfix [...], where many
short arguments would cause [...] find -exec .. {} + to fail")
4.2.28 (Aug 2006) ("find does not subtract environment size")

Some systems don't provide this feature, although you might have
expected it: IRIX (at least up to 6.5.22) and Reliant UNIX (5.43).
Either this feature can be deactivated at compile time or - more
likely - find originates from pre-SVR4 on these systems.
--
<http://www.in-ulm.de/~mascheck/various/find/>

Geoff Clare

unread,
Jun 18, 2007, 9:23:16 AM6/18/07
to
Sven Mascheck wrote:

[about -exec ... {} +]

> - documented to be syntactically accepted on AIX 5.3 (from the manpage,
> but i don't know yet, if it's actually implemented)

It must be. AIX 5.3 is certified as UNIX03 conforming, and the
Open Group's VSC test suite includes tests of that feature.

Likewise Mac OS X Version 10.5 (Leopard) was recently UNIX03
certified, so it must be implemented there as well.

--
Geoff Clare <net...@gclare.org.uk>

0 new messages